Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By lsolesen on
Is it possible to have contextual links on the title / headline of a node instead of printing the tabs (view and edit) underneath.
Comments
Bump
Anybody knows this?
This is starting point
Contextual links for nodes configured by
node_view()
So, I just added to my theme
Not sure it is right to remove all limitations in
node_view()
, but it works.Why it does not show contextual links for "except when the node is already being displayed on its own page"?
One issue is that not all links from tabs displayed in contextual menu.
For example "Devel" link is not displayed.
Looks like modules should have integration with this feature.
Modules should implement
hook_menu_contextual_links_alter()
to add contextual menu items.There is also contextual links generated by
menu_contextual_links()
This implementation does not include links with
MENU_CONTEXT_NONE
andMENU_CONTEXT_PAGE
.Once again I do not understand why menu items with
MENU_CONTEXT_PAGE
excluded?So, as a temporary solution, I also added
hook_menu_contextual_links_alter()
to my theme:It is definitely hacking, but I can't wait for module developers.
If this will not work - make sure you have following line in your
node.tpl.php
ornode--CONTENT_TYPE.tpl.php
(this line already exists in core implementation, so, I am concerned about customized templates):A solution
All you have to do is put appropriate classes around the local tasks' (i.e. tabs') HTML and jQuery will do the rest.
I did it from my template's template.php:
And then add to the content DIV (in your page.tpl.php file) a new class "contextual-links-region", then clear cache and voilà!
This code does it only for the primary tabs, though. But if you want, you can combine the primary and secondary tabs into one array and render it as one. I just didn't have a need for secondary tabs as for now.
Very nice solution minff.
Very nice solution minff.
Coolest thing I read all day
Coolest thing I read all day :)
Very simplified solution
Very simplified solution minff... thanks for sharing.
I do have a one modification to the code for the "THEMENAME_menu_local_tasks" function that I would like to share.
The additional code will display the default tabs if the current user doesn't have access to contextual links.
Additional code:
Full code:
Small correction
The above code adds one div to much if the user does not have the correct permissions.
Change
To
each of this examples,
each of this examples, convert any tab to contextual links. But in my case, i only want contextual links on node view page.
i'll explain myself better. I use view to create tabbed navigation, so, using any of this snippets, the tabs are converted to contextual links.
so, how can i solve this problem? convert to contextual links only tabs on node view page?
An addition
Actually there's one addition to be made: remove the "View" contextual link when displaying a node. Because, well, you don't need it when you're already viewing the node. One way to do this is to change THEMENAME_menu_local_task() into this:
Created small article
I created a small article about this post. http://larsolesen.dk/node/317
Complement for Omega theme
Very nice.
One complement for those using Omega theme.
You need the following function in the region preprocessor
preprocess-region.inc
in order to add the relevant class for contextual links.Laurent
user/%/view
This can also be interesting, now it works for every enity that has a page with tabs
Add contextual-links library first
I found I didn't have the contextual links js available by default, so just got the unstyled links.
This version works for me, just the drupal_add_library line added
thanks,
DT
Thanks
worked perfect for me, just what i was looking for!
Custom Drupal Development
Great thread. I've taken an
Great thread.
I've taken an extra step in my theme and moved the contextual links from page.tpl.php into the #block-system-main block. I'm using a forked version of the Omega theme, with the following changes:
In preprocess-block.inc:
This adds the .contextual-links-region class to the block.
In block.tpl.php:
This renders the tabs inside the block, using the code above.
With these additions, I was able to remove tabs from page.tpl.php entirely.
A good idea. Using panels and
A good idea. Using panels and hiding the original title for the page - the h1 - with css to be able to decide for myself where the title is rendered the contextual links disappears when the contextual links are in page.tpl.php.
To make it easier to implement for other people, maybe both things can be achieved with a preprocess function?
Still not working for panels pages
That does still not solve my problem for panel pages. Another issue is that the title is not displayed in the block (for whatever reason that is) which means that the contextual links will not display exactly where it is expected.
Dumb Question
I am using skeletontheme and my content div has a class already defined:
Im not an expert at this kind of thing but I am trying to learn. I can see that if I change it to class "contextual-links-region" it works but it messes up all the alignment of my theme. Just wondered if someone could explain how I could get round this?
Solved it myself!
Pleasingly I solved it myself, disappointing it seems my html skills were to blame as I didn't know you could just add multiple classes with a space! Still, at least I learnt something!
TabsNoMore
Announcing a Drupal 7 module which converts tabs to contextual links.
Module's name: TabsNoMore
URL: http://drupal.org/sandbox/onkeltem/1730244
TabsNoMore Thank you for
Thank you for this! Works as expected out of the box. One little glitch:
The "View" tab content is displayed for user with no editing/admin rights. Any way to fix this?
Thanks for reporting this.I
Thanks for reporting this.
I was not checking user access to "access contextual links" permission unconditionally printing links for all available tabs.
Now it is fixed:
http://drupalcode.org/sandbox/onkeltem/1730244.git/commit/7c79fde
Now if a user has no access to contextual links, tabsnomore_acitve() will return false and links would render as before.
Hi OnkelTem, That
Hi OnkelTem,
That worked!
Thank you so much for the quick response!
Jorge
Promote to full project
Are you going to promote this to a full project soon?
Aye!
Aye!
Hi OnkelTem! Now that I think
Hi OnkelTem!
Now that I think of it, since the contextual menus always appear in the node view mode, the "View" tab should never be shown, regardless of the user role (anonymous or not).
Great module!
Jorge
Simple Solution
I find this to be a simple solution.
Still requires to you to add
As outlined above in other comments, the above code is elegant simple, but still requires to you to add the class 'contextual-links-region' to the main content div in your page.tpl.php template to show up - as I've tried to replicate this for a different theme.