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]);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JohnAlbin’s picture

Assigned: Unassigned » JohnAlbin
FileSize
940 bytes

And here's the correct patch.

Interesting that you can edit a comment but not the original posting. :-)

JohnAlbin’s picture

The 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 wrapping

around 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.

yettyn’s picture

Status: Needs review » Needs work

This 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.

JohnAlbin’s picture

Status: Needs work » Needs review
FileSize
1.54 KB

Not far enough!

Here’s the new patch. Thanks for reviewing, Joakim!

dvessel’s picture

Title: default local task is missing attributes during theme_menu_local_task() » regression: local tasks is missing attributes for theming.

This is a regression so marking it as such. I had a patch for this but I lost it. :)

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

the theme function still receives title and href as before so no API change. looks worthwhile to me.

yettyn’s picture

and now it works as well :-)

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

jenlampton’s picture

Version: 6.x-dev » 8.x-dev
Status: Closed (fixed) » Active
Issue tags: +Needs backport to D7

The 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".

return '<li' . (!empty($variables['element']['#active']) ? ' class="active"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . "</li>\n";

(see the whole function)

Jaypan’s picture

Title: regression: local tasks is missing attributes for theming. » Local tasks do not accept #attributes for themeing
Assigned: JohnAlbin » Jaypan
Status: Active » Needs review
FileSize
1.22 KB

Yes. 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.

Status: Needs review » Needs work
Issue tags: -Needs backport to D7

The last submitted patch, drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch, failed testing.

Jaypan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch, failed testing.

Jaypan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch, failed testing.

Jaypan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch, failed testing.

Jaypan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +Needs backport to D7

The last submitted patch, drupal-8.x_local_tasks_cannot_receive_attributes-207029-11.patch, failed testing.

Jaypan’s picture

It 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?

Jaypan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Jaypan’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.26 KB

Updating with new re-rolled patch for current version of D8.

Jaypan’s picture

Assigned: Jaypan » Unassigned

Removing myself from the assignment in the hopes that it will garner some attention for this issue.

dawehner’s picture

Should we write some tests for that?

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs reroll

Status: Needs work » Needs review

Status: Needs review » Needs work
neetu morwani’s picture

Assigned: Unassigned » neetu morwani
Issue tags: +#punedrupalgroup, +#SprintWeekend2015
neetu morwani’s picture

Assigned: neetu morwani » Unassigned
Gábor Hojtsy’s picture

Issue tags: -#SprintWeekend2015 +SprintWeekend2015

Tag does not include #

neetu morwani’s picture

Assigned: Unassigned » neetu morwani
piyuesh23’s picture

Status: Needs work » Needs review

Looks 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]

jhedstrom’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Needs review » Needs work

I agree with #34 that this has been fixed in 8.x via twig templates. Moving back to 7.x.

mrjmd’s picture

Status: Needs work » Needs review
FileSize
1.23 KB

Here's an attempt at backporting this to d7.

mrjmd’s picture

Assigned: neetu morwani » Unassigned

  • Gábor Hojtsy committed 2360796 on 8.3.x
    #207029 by JohnAlbin: some menu item properties were not passed along...

  • Gábor Hojtsy committed 2360796 on 8.3.x
    #207029 by JohnAlbin: some menu item properties were not passed along...

  • Gábor Hojtsy committed 2360796 on 8.4.x
    #207029 by JohnAlbin: some menu item properties were not passed along...

  • Gábor Hojtsy committed 2360796 on 8.4.x
    #207029 by JohnAlbin: some menu item properties were not passed along...
vijaycs85’s picture

Latest 7.x patch still apply. So updating tags accordingly. Probably we still need tests.

  • Gábor Hojtsy committed 2360796 on 9.1.x
    #207029 by JohnAlbin: some menu item properties were not passed along...