How to Master Contextual Links On Your Drupal Website
While developing Drupal websites, I have been faced with the problem of adding custom contextual links to different elements like: taxonomy terms displayed as rendered entities, blocks created with Ctools plugins, custom blocks and other.
Contextual links are links attached to elements such as nodes, blocks, views displays and others. When you hover on a specific region, a gear image appears. Upon clicking it, the image shows the list of contextual links. You can see an example below.
Some modules provide contextual links that allow users to edit views, nodes, taxonomies and other elements, but there are situations when contextual links need to be created in a custom implementation.
Add a Custom Contextual Link to the Taxonomy Term View
In my case, I have a view that shows Taxonomy terms from the Service Category vocabulary as Rendered entities, without fields.
For each term, a contextual link should be added to the page where the term information can be edited, and the link would allow privileged users access to that page. This task can be accomplished using template_preprocess_taxonomy_term() to edit variables that will be used in the template file (taxonomy-term.tpl.php or taxonomy-term–service_category.tpl.php) and hook_contextual_links_view_alter(). In the preprocess function, the contextual link element can be added in the $title_suffix array.
In hook_contextual_links_view_alter() are the altered contextual links elements before they are rendered. In this case, a new link is added.
An important thing is that a class should be added for the region wrapper that includes contextual links. This class is contextual-links-region, and it makes it possible to show the contextual links region when you hover on the gear icon.
As a result, the taxonomy term entities will be displayed with a contextual link that will allow users that have administer taxonomy permission to access the term edit page.
Custom Contextual Links as Render Elements
Contextual links can be added to elements like blocks using a renderable array. For example:
Theme function in the example is used to add a template where the wrapper with the contextual-links-region class will be added:
And the content of the template file:
Finally, the result will be a block in which content is wrapped with a contextual link region. Clicking on the gear icon will display the link to the vocabulary edit page.
You can find more info here: https://drupal.org/documentation/modules/contextual . Please post any comments below. And make sure to subscribe to our mailing list to receive our blog feed.
Source: http://wearepropeople.com/blog/how-to-master-contextual-links-on-your-drupal-website
Anyone can join.
Anyone can contribute.
Anyone can become informed about their world.
"United We Stand" Click Here To Create Your Personal Citizen Journalist Account Today, Be Sure To Invite Your Friends.
Before It’s News® is a community of individuals who report on what’s going on around them, from all around the world. Anyone can join. Anyone can contribute. Anyone can become informed about their world. "United We Stand" Click Here To Create Your Personal Citizen Journalist Account Today, Be Sure To Invite Your Friends.
LION'S MANE PRODUCT
Try Our Lion’s Mane WHOLE MIND Nootropic Blend 60 Capsules
Mushrooms are having a moment. One fabulous fungus in particular, lion’s mane, may help improve memory, depression and anxiety symptoms. They are also an excellent source of nutrients that show promise as a therapy for dementia, and other neurodegenerative diseases. If you’re living with anxiety or depression, you may be curious about all the therapy options out there — including the natural ones.Our Lion’s Mane WHOLE MIND Nootropic Blend has been formulated to utilize the potency of Lion’s mane but also include the benefits of four other Highly Beneficial Mushrooms. Synergistically, they work together to Build your health through improving cognitive function and immunity regardless of your age. Our Nootropic not only improves your Cognitive Function and Activates your Immune System, but it benefits growth of Essential Gut Flora, further enhancing your Vitality.
Our Formula includes: Lion’s Mane Mushrooms which Increase Brain Power through nerve growth, lessen anxiety, reduce depression, and improve concentration. Its an excellent adaptogen, promotes sleep and improves immunity. Shiitake Mushrooms which Fight cancer cells and infectious disease, boost the immune system, promotes brain function, and serves as a source of B vitamins. Maitake Mushrooms which regulate blood sugar levels of diabetics, reduce hypertension and boosts the immune system. Reishi Mushrooms which Fight inflammation, liver disease, fatigue, tumor growth and cancer. They Improve skin disorders and soothes digestive problems, stomach ulcers and leaky gut syndrome. Chaga Mushrooms which have anti-aging effects, boost immune function, improve stamina and athletic performance, even act as a natural aphrodisiac, fighting diabetes and improving liver function. Try Our Lion’s Mane WHOLE MIND Nootropic Blend 60 Capsules Today. Be 100% Satisfied or Receive a Full Money Back Guarantee. Order Yours Today by Following This Link.
