本文介绍了如何在drupal中获取某个父项下的所有菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我真的只需要某个菜单项下第一级的 mlid 和标题文本.这就是我目前正在做的事情.(它有效,但我怀疑可能有更像 drupal 的方式.):
I really only need the mlid and title text for the first level below a certain menu item. Here's what I'm doing at the moment. (It works, but I suspect there may be a more drupal-y way.):
/**
* Get all the children menu items below 'Style Guide' and put them in this format:
* $menu_items[mlid] = 'menu-title'
* @return array
*/
function mymod_get_menu_items() {
$tree = menu_tree_all_data('primary-links');
$branches = $tree['49952 Parent Item 579']['below']; // had to dig for that ugly key
$menu_items = array();
foreach ($branches as $menu_item) {
$menu_items[$menu_item['link']['mlid']] = $menu_item['link']['title'];
}
return $menu_items;
}
有吗?
推荐答案
afaik,没有(我希望我错了).暂时,您可以通过简单地添加一个 foreach ($tree) 将您的函数变成一个更抽象的辅助函数,而不是挖掘丑陋的键.然后你可以使用你自己的逻辑来输出你想要的东西(在这种情况下是 mlid).这是我的建议:
afaik, there isn't (i hope i am wrong).for the while, instead of digging for ugly keys, you can turn your function into a more abstract helper function by simply adding a foreach ($tree). then you can use your own logic to output what you want (mlid, in this case). here is my suggestion:
/**
* Get the children of a menu item in a given menu.
*
* @param string $title
* The title of the parent menu item.
* @param string $menu
* The internal menu name.
*
* @return array
* The children of the given parent.
*/
function MY_MODULE_submenu_tree_all_data($title, $menu = 'primary-links') {
$tree = menu_tree_all_data($menu);
foreach ($tree as $branch) {
if ($branch['link']['title'] == $title) {
return $branch['below'];
}
}
return array();
}
这篇关于如何在drupal中获取某个父项下的所有菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!