37 throw new ElggInvalidArgumentException(__CLASS__ .
' expects an instanceof of ' . MenuItems::class);
50 public function getMenu($sort_by =
'priority') {
65 $menu_item = $this->items->get($item_name);
70 $menu_item->setSelected();
91 return $item->inContext();
121 return $item->getSection();
124 $section_ids = array_unique(array_values($section_ids));
126 foreach ($section_ids as
$index => $section_id) {
128 return $item->getSection() == $section_id;
131 $section = new \Elgg\Menu\MenuSection();
156 $all_menu_items = [];
161 $parent_name = $menu_item->getParentName();
162 $menu_item_name = $menu_item->getName();
166 $parents[$menu_item_name] = $menu_item;
171 $all_menu_items[$menu_item_name] = $menu_item;
174 if (empty($all_menu_items)) {
179 if (empty($parents)) {
188 foreach (
$children as $menu_item_name => $menu_item) {
189 $parent_name = $menu_item->getParentName();
191 if (!array_key_exists($parent_name, $all_menu_items)) {
202 if (!in_array($menu_item, $all_menu_items[$parent_name]->getData(
'children'))) {
203 $all_menu_items[$parent_name]->addChild($menu_item);
204 $menu_item->setParent($all_menu_items[$parent_name]);
207 $message =
_elgg_services()->translator->translate(
'ElggMenuBuilder:Trees:DuplicateChild', [$menu_item_name]);
213 $parents = array_values($parents);
225 foreach ($this->items as $menu_item) {
226 if ($menu_item->getSelected()) {
242 $menu->sort(
function (\
Elgg\Menu\MenuSection $s1, \
Elgg\Menu\MenuSection $s2) {
243 return strnatcmp($s1->getID(), $s2->getID());
253 $indices = array_keys(
$section->all());
256 $item->setData(
'original_order', array_search(
$item->getID(), $indices));
257 $item->sortChildren($sorter);
274 return [self::class,
'compareByText'];
277 return [self::class,
'compareByName'];
280 return [self::class,
'compareByPriority'];
283 return $sort_by && is_callable($sort_by) ? $sort_by :
null;
296 $at = strip_tags($a->getText());
297 $bt = strip_tags($b->getText());
301 return $a->getData(
'original_order') - $b->getData(
'original_order');
321 return $a->getData(
'original_order') - $b->getData(
'original_order');
337 $aw = $a->getPriority();
338 $bw = $b->getPriority();
341 return $a->getData(
'original_order') - $b->getData(
'original_order');
Exception thrown if an argument is not of the expected type.
_elgg_services()
Get the global service provider.