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.
Below function removes $item['options']['unaltered_hidden'] if a menu item is not for FIRSTCHILD like https://www.drupal.org/project/menu_inject_block
However, it may be altered by another module. The line should be removed.
Reminder: the hook is only used when adding/changing a menu link and saving it in the database.
/**
* Implementation of hook_menu_link_alter().
*/
function menu_firstchild_menu_link_alter(&$item, $menu) {
if (@$item['module'] == 'menu') {
if ($item['link_path'] == '<firstchild>') {
$item['options']['alter'] = TRUE;
$item['options']['unaltered_hidden'] = $item['hidden'];
}
else {
unset($item['options']['unaltered_hidden']); // <-- This should be removed.
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#3 | menu_firstchild_2564289_3_hook_menu_link_alter.patch | 1.17 KB | johnv |
Comments
Comment #2
johnvComment #3
johnvPlease see attached patch, that corrects hook_menu_link_alter. THis hook is called when saving a menu link from the menu overview form.
It contains:
1- A correction of the routine interface as mentioned in #1816870: Drupal 6 usage of menu_link_alter() - D7 doesn't pass $menu to it.
2- A typo (?) in @$item['module'] as mentioned in #2564287: typo in menu_firstchild_menu_link_alter() ?
3- Removes fiddling with $item['options']['unaltered_hidden']. The menu item may not be yours. It could be if is replaced,
I know, issues should not be mixed, but this issues queue is rather small, and all changes are very close together.
Comment #4
Chris Matthews CreditAttribution: Chris Matthews commentedThe 3 year old patch in #3 applied cleanly to the latest 7.x-1.x dev snapshot and works well for me so changing the status to RTBC.
Comment #6
anrikun CreditAttribution: anrikun commented@Chris Matthews
Could you review the latest 7.x-1.x to ensure everything is ok for a new stable release?
Comment #7
anrikun CreditAttribution: anrikun commented