挂钩菜单以取消设置 link 条件
Hook menu to unset a link with conditions
我在 Drupal 7 上遇到了问题。
我的主菜单包含多个链接。
使用模块 menu_fields,我向菜单链接添加了分类法,我想根据所选的菜单更改此菜单显示。
问题是我不知道怎么写我的开发。
我在我的模块中测试了 hook_menu(), hook_menu_alter(), hook_menu_alter_link() 但是我写的 dpm() 从来没有出现过。
我希望得到一个带有包含菜单项数组的参数的挂钩。
你有什么想法吗?
Progress:
I manage to display something with hook_menu_alter() -I had to empty cache- but I can't find the main menu in the $items var.
我能想到的最好的解决方案是用menu_tree_all_data()
函数收集菜单树:
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_all_data/7.x
然后爬取树结构(递归)并手动生成菜单html。
问题已使用 mymodule_translated_menu_link_alter(&$item, $map)
解决。
您只需执行 if ($item['menu_name'] == 'main-menu') {}
语句并在其中添加您的代码。
我在 Drupal 7 上遇到了问题。
我的主菜单包含多个链接。 使用模块 menu_fields,我向菜单链接添加了分类法,我想根据所选的菜单更改此菜单显示。
问题是我不知道怎么写我的开发。
我在我的模块中测试了 hook_menu(), hook_menu_alter(), hook_menu_alter_link() 但是我写的 dpm() 从来没有出现过。
我希望得到一个带有包含菜单项数组的参数的挂钩。
你有什么想法吗?
Progress: I manage to display something with hook_menu_alter() -I had to empty cache- but I can't find the main menu in the $items var.
我能想到的最好的解决方案是用menu_tree_all_data()
函数收集菜单树:
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_all_data/7.x
然后爬取树结构(递归)并手动生成菜单html。
问题已使用 mymodule_translated_menu_link_alter(&$item, $map)
解决。
您只需执行 if ($item['menu_name'] == 'main-menu') {}
语句并在其中添加您的代码。