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.
It is impossible to theme menus differently. You need developer skills and a fair amount of knowledge about the menu system to alter the output of a certain menu.
Attached patch fixes this bug by leveraging the theme system's capability of theme function suggestions.
No API change, no functional change, just an additional theme suggestion.
Comment | File | Size | Author |
---|---|---|---|
#14 | drupal.menu-theme.14.patch | 1.11 KB | effulgentsia |
#2 | drupal.menu-theme.2.patch | 1.15 KB | sun |
drupal.menu-theme.patch | 1.28 KB | sun | |
Comments
Comment #1
sunJust found #588148: theme_links() is not really themeable, which tries to do the same to theme_links.
Comment #2
sunUpdated for the more failsafe naming standard mentioned in #588148: theme_links() is not really themeable
Comment #3
mooffie CreditAttribution: mooffie commentedIn addition to your proposal,
Wouldn't it be nice to do
drupal_alter('menu_tree_output', $output, $menu_name)
on the result of menu_tree_output()?Rationale:
Overriding theme_menu_link() and theme_menu_tree() is nice, but inside these two functions you still don't know about the surrounding items. E.g., inside theme_menu_link() you don't know your position so you can't add 'odd' / 'even' classes.
Comment #4
sunFor that, you can use http://api.drupal.org/api/function/hook_block_view_alter/7
Comment #5
sunAnything left here?
Comment #7
catchMarked #408148: Create sub-theme functions for rendering menus as dup.
Comment #8
sunSo is this RTBC?
Comment #9
catchLooks great. We're a bit too late for #408150: Add "Welcome, $username" to user links but still nice to have
Comment #10
effulgentsia CreditAttribution: effulgentsia commentedPlease also see #653622: Make the '__' pattern for theme suggestions easier to use.
Comment #12
effulgentsia CreditAttribution: effulgentsia commentedas per #9
Comment #13
webchickI committed #653622: Make the '__' pattern for theme suggestions easier to use. This one will need a re-roll.
Comment #14
effulgentsia CreditAttribution: effulgentsia commentedre-rolled.
Comment #15
webchickIn retrospect, it's probably a bit late for all three of these patches, but since I committed the first in the series, I guess we might as well finish the set. At least it doesn't break anything. :) (famous last words)
Committed to HEAD. Needs documenting in the theme upgrade guide.
Comment #16
effulgentsia CreditAttribution: effulgentsia commentedI started to document this, but stopped, realizing that a bug that was fixed in D6, but not yet in D7 is preventing this particular use-case from working. I think it makes sense to have #241570: Theme preprocess functions do not get retained when using patterns get resolved before telling theme developers about this cool new toy that doesn't work yet.
Comment #17
effulgentsia CreditAttribution: effulgentsia commentedChanging status to reflect #16.
Comment #18
hass CreditAttribution: hass commented#338027: Better menu template suggestion has been marked as duplicate
Comment #19
effulgentsia CreditAttribution: effulgentsia commented#241570: Theme preprocess functions do not get retained when using patterns landed, so: http://drupal.org/update/theme/6/7#theme-suggestions-for-menus.
Please see #588148-39: theme_links() is not really themeable for a still open question about how to best document the same for theme_links().
Comment #21
frogrod CreditAttribution: frogrod commentedit doesn't work when the menu name is longer than one word.
[menu_name] => secondary-menu
you can't have dashes in php function names
themeName_menu_link__management -works
but it never pics up the secondary menu
intel_agate_menu_link__secondary_menu it's trying to match the - and not an underscore.
Comment #22
jitse CreditAttribution: jitse commentedI would like to confirm #21.
As PHP does not allow dashes in function signatures using the proposed naming method does not work for newly created menus as new menunames are always prepended with menu.
No time to look into the theme suggestions so no further contributions there.
Comment #23
Elijah Lynn