When local tasks are themed, the default local task gets passed to theme_menu_local_task()
using a stitched together array that only contains 'title' and 'href'.
$link = theme('menu_item_link', array('title' => $item['title'], 'href' => $tasks[$p]['href']));
Unfortunately, if you want to override theme_menu_local_task()
you won’t have access to the myriad of array keys that are missing from the default local task but are available for the other local tasks. For example, you can’t check for $link['type'] & MENU_IS_LOCAL_TASK
because the default local task doesn't have a 'type' key.
The attached patch uses:
$link = theme('menu_item_link', array('href' => $tasks[$p]['href']) + $item);
I’ve only been looking at chx’s menu code for about an hour, so I'm not sure if this is the best solution. An alternative might be:
$link = theme('menu_item_link', array('href' => $item['title']) + $tasks[$p]);
Comments
Comment #1
JohnAlbinAnd here's the correct patch.
Interesting that you can edit a comment but not the original posting. :-)
Comment #2
JohnAlbinThe easy way to review this patch is to install the HEAD version of Zen (http://drupal.org/node/96810), which makes use of
MENU_IS_LOCAL_TASK
to add a wrappingaround each tab link in order to get pretty image-based tabs.
Then just go to any page with tabs on your D6 site to see the before (PHP Notice and un-styled tab) and after (fixed!) when applying this patch.
Comment #3
yettyn CreditAttribution: yettyn commentedThis patch appears to fix only the first tab, clicking 2nd, 3rd etc. results in,
notice: Undefined index: type in /var/www/www.astrocalc.com/htdocs/sites/all/themes/zen/template-menus.php on line 20.
using the zen-6.x-dev theme, so either the patch is wrong solution or it doesn't go far enough, so to speak.
Comment #4
JohnAlbinNot far enough!
Here’s the new patch. Thanks for reviewing, Joakim!
Comment #5
dvessel CreditAttribution: dvessel commentedThis is a regression so marking it as such. I had a patch for this but I lost it. :)
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedthe theme function still receives title and href as before so no API change. looks worthwhile to me.
Comment #7
yettyn CreditAttribution: yettyn commentedand now it works as well :-)
Comment #8
Gábor HojtsyCommitted, thanks.
Comment #9
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #10
jenlamptonThe attributes on local task LI tags seem to have gotten lost somwhere along the way. It looks like the only class that will ever get added now is "active".
(see the whole function)
Comment #11
Jaypan CreditAttribution: Jaypan commentedYes. This thread appears to have been closed at sometime in D6, but the problem has persisted into D7 and D8.
I am attaching a patch for D8 that allows for #attributes that are passed to theme_menu_local_task() to be incorporated into the HTML.
Comment #13
Jaypan CreditAttribution: Jaypan commented#11: drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch queued for re-testing.
Comment #15
Jaypan CreditAttribution: Jaypan commented#11: drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch queued for re-testing.
Comment #17
Jaypan CreditAttribution: Jaypan commented#11: drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch queued for re-testing.
Comment #19
Jaypan CreditAttribution: Jaypan commented#11: drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch queued for re-testing.
Comment #21
Jaypan CreditAttribution: Jaypan commentedIt looks like the testing system is down - I don't see that it even gets to the point that Drupal is fired up, so I don't think that the problem can be with my patch. Can someone else take a look at this?
Comment #22
Jaypan CreditAttribution: Jaypan commented11: drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch queued for re-testing.
Comment #24
Jaypan CreditAttribution: Jaypan commentedUpdating with new re-rolled patch for current version of D8.
Comment #25
Jaypan CreditAttribution: Jaypan commentedRemoving myself from the assignment in the hopes that it will garner some attention for this issue.
Comment #26
dawehnerShould we write some tests for that?
Comment #27
jhedstromComment #30
neetu morwani CreditAttribution: neetu morwani commentedComment #31
neetu morwani CreditAttribution: neetu morwani commentedComment #32
Gábor HojtsyTag does not include #
Comment #33
neetu morwani CreditAttribution: neetu morwani commentedComment #34
piyuesh23 CreditAttribution: piyuesh23 commentedLooks like this has already been moved into core. menu-local-task.html.twig takes care of adding attributes. [core/modules/system/templates/menu-local-task.html.twig]
Comment #35
jhedstromI agree with #34 that this has been fixed in 8.x via twig templates. Moving back to 7.x.
Comment #36
mrjmd CreditAttribution: mrjmd commentedHere's an attempt at backporting this to d7.
Comment #37
mrjmd CreditAttribution: mrjmd commentedComment #42
vijaycs85Latest 7.x patch still apply. So updating tags accordingly. Probably we still need tests.