50 public function getMenu($sort_by =
'priority') {
65 $menu_item = $this->items->get($item_name);
70 $menu_item->setSelected();
124 $section_ids = array_unique(array_values($section_ids));
126 foreach ($section_ids as
$index => $section_id) {
131 $section = new \Elgg\Menu\MenuSection();
156 $all_menu_items = [];
159 foreach ($section as $menu_item) {
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);
215 $section->fill($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());
252 return $menu->
walk(
function (\
Elgg\Menu\MenuSection
$section) use ($sorter) {
253 $indices = array_keys($section->all());
256 $item->
setData(
'original_order', array_search($item->
getID(), $indices));
260 $section->sort($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');
map(callable $callback)
{Walk through all items in the collection and apply a callback.Mappermixed}
walk(callable $callback)
Walk through members of the collection and apply a callback.
_elgg_services()
Get the global service provider.
filter(callable $callback=null)
{Filter collection items using a custom filter Returns a new collection instance.Filterstatic} ...
sort(callable $callback=null)
{Sort fields using custom callable If not provided, will sort items by priority.Sorterstatic} ...