setChildren() public method

This is reserved for the \ElggMenuBuilder.
public setChildren ( ElggMenuItem[] $children ) : void
$children ElggMenuItem[] Array of items
return void
Example #1
0
 /**
  * Reorders menu item and adds an add button
  *
  * @param \ElggMenuItem $item  menu item
  * @param int           $depth depth of the menu item
  *
  * @return \ElggMenuItem
  */
 private static function orderMenuItem(\ElggMenuItem $item, $depth)
 {
     $depth = (int) $depth;
     $children = $item->getChildren();
     if (empty($children)) {
         return $item;
     }
     // sort children
     $ordered_children = [];
     foreach ($children as $child) {
         $child = self::orderMenuItem($child, $depth + 1);
         $child_priority = $child->getPriority();
         while (array_key_exists($child_priority, $ordered_children)) {
             $child_priority++;
         }
         $ordered_children[$child_priority] = $child;
     }
     ksort($ordered_children);
     $item->setChildren($ordered_children);
     return $item;
 }
Example #2
0
/**
 * Reorders menu item and adds an add button
 *
 * @param ElggMenuItem $item  menu item
 * @param int          $depth depth of the menu item
 *
 * @return ElggMenuItem
 */
function menu_builder_order_menu_item(ElggMenuItem $item, $depth)
{
    $depth = (int) $depth;
    if ($children = $item->getChildren()) {
        // sort children
        $ordered_children = array();
        foreach ($children as $child) {
            $child = menu_builder_order_menu_item($child, $depth + 1);
            $child_priority = $child->getPriority();
            while (array_key_exists($child_priority, $ordered_children)) {
                $child_priority++;
            }
            $ordered_children[$child_priority] = $child;
            if (isset($_SESSION["menu_builder_edit_mode"]) && $depth < 5) {
                // add button
                $child_add = ElggMenuItem::factory(array("name" => 'menu_builder_add', "text" => elgg_view_icon("round-plus"), "href" => '/menu_builder/edit?parent_guid=' . $child->getName(), "class" => "menu_builder_add_link", "title" => elgg_echo("menu_builder:edit_mode:add")));
                $child->addChild($child_add);
            }
        }
        ksort($ordered_children);
        $item->setChildren($ordered_children);
    }
    return $item;
}