50 public function getMenu($sort_by =
'priority') {
65 $menu_item = $this->items->get($item_name);
70 $menu_item->setSelected();
125 $section_ids = array_unique(array_values($section_ids));
127 foreach ($section_ids as
$index => $section_id) {
132 $section = new \Elgg\Menu\MenuSection();
157 $all_menu_items = [];
160 foreach ($section as $menu_item) {
162 $parent_name = $menu_item->getParentName();
163 $menu_item_name = $menu_item->getName();
167 $parents[$menu_item_name] = $menu_item;
172 $all_menu_items[$menu_item_name] = $menu_item;
175 if (empty($all_menu_items)) {
180 if (empty($parents)) {
189 foreach (
$children as $menu_item_name => $menu_item) {
190 $parent_name = $menu_item->getParentName();
192 if (!array_key_exists($parent_name, $all_menu_items)) {
203 if (!in_array($menu_item, $all_menu_items[$parent_name]->getData(
'children'))) {
204 $all_menu_items[$parent_name]->addChild($menu_item);
205 $menu_item->setParent($all_menu_items[$parent_name]);
208 $message =
_elgg_services()->translator->translate(
'ElggMenuBuilder:Trees:DuplicateChild', [$menu_item_name]);
215 $parents = array_values($parents);
217 $section->fill($parents);
227 foreach ($this->items as $menu_item) {
228 if ($menu_item->getSelected()) {
244 $menu->
sort(
function (\
Elgg\Menu\MenuSection $s1, \
Elgg\Menu\MenuSection $s2) {
245 return strnatcmp($s1->getID(), $s2->getID());
254 return $menu->
walk(
function (\
Elgg\Menu\MenuSection
$section) use ($sorter) {
255 $indices = array_keys($section->all());
258 $item->
setData(
'original_order', array_search($item->
getID(), $indices));
262 $section->sort($sorter);
276 return [\ElggMenuBuilder::class,
'compareByText'];
279 return [\ElggMenuBuilder::class,
'compareByName'];
282 return [\ElggMenuBuilder::class,
'compareByPriority'];
285 return $sort_by && is_callable($sort_by) ? $sort_by : null;
298 $at = strip_tags($a->getText());
299 $bt = strip_tags($b->getText());
303 return $a->getData(
'original_order') - $b->getData(
'original_order');
323 return $a->getData(
'original_order') - $b->getData(
'original_order');
339 $aw = $a->getPriority();
340 $bw = $b->getPriority();
343 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} ...