how to get all the menu items below a certain parent in drupal?

前端 未结 5 1724
醉梦人生
醉梦人生 2021-02-01 23:32

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 dru

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 23:57

    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();
    }
    

提交回复
热议问题