Hello,

I want to get all the children mlids of a specific parent item.
I have tested several drupal function without results.
Is it possible to get the children mlids of a parent item ?
Which function do I use for this ?

Thanks for your help.

Comments

nevets’s picture

What is your goal for a non-technical perspective, are you trying to get all the menu children of the currently active menu item?

kumkum29’s picture

Hello,

it's a little complicated. I have an important number of node (news) in a parent node (news list).
When I edits a node, the list options of the menu are too important and the menu list is not easy to use. I want hide the childrens of this "news list" page in this menu.
I have the mlid of the parent item (news list), but I want to get all the mlids of the childrens for hide these nodes in the list of the menu.

Thanks.

noita’s picture

Hi,

I know that come really late but if that can help anyone, this is the function that I use to create an array with mlid from a simple mlid:

/**
 * This function return all children for the mlid define into the mlid parameter
 *
 * @param $mlid
 *  Give Array with the mlid that you want to define the children.
 *    E.G : $mlid = array( 1373 => 1373 );
 * @param $tree
 *  Give menu_tree_all_data('MyMenu');
 * @param $data
 *  Parameter use to add mlid for child, give empty array.
 */
function MYMODULE_menu_get_child(& $mlid, $tree, & $data) {
  foreach ($tree as $child) {
    if ((in_array($child['link']['plid'], $mlid) || in_array($child['link']['mlid'], $mlid))) {
      $mlid = $mlid + array(
          "" . $child['link']['plid'] => $child['link']['plid'],
          "" . $child['link']['mlid'] => $child['link']['mlid']
        );
      $data = $data + array(
          "" . $child['link']['plid'] => $child['link']['plid'],
          "" . $child['link']['mlid'] => $child['link']['mlid']
        );
      unset($mlid[0]);
      unset($data[0]);
      if (!empty($child['below'])) {
        MYMODULE_menu_get_child($mlid, $child['below'], $data);
      }
    }
  }
}

And if you need to integrate it:

$tree = menu_tree_all_data('MY_MENU_NAME');
$data = array();
$mlid = array('1374' => 1374); //1374 is an example of mlid
MYMODULE_menu_get_child($mlid, $tree, $data);
if (is_array($data) && !empty($data)) {
   foreach ($data as $mlid) {
     //do what you want with child
     dsm($mlid);
   }
}

Hope that help anyone !