Get elements given a stage and the code of the menu.

@param string $menuCode Menu code
@param string $stage    Stage

@return array Elements
198841
public function getElementsByMenuCodeAndStage(
        $menuCode,
        $stage
    ) {
        $elementsByMenuCode = isset($this->elementsStoredByMenuCode[$menuCode])
            ? $this->elementsStoredByMenuCode[$menuCode]
            : [];

        $elementsByStage = isset($this->elementsStoredByStage[$stage])
            ? $this->elementsStoredByStage[$stage]
            : [];

        $elements = array_values(
            array_intersect_key(
                array_merge(
                    $this->allElements,
                    $elementsByMenuCode
                ),
                $elementsByStage
            )
        );

        usort($elements, function ($element1, $element2) {
            $element1Id = spl_object_hash($element1);
            $element2Id = spl_object_hash($element2);

            return $this->priorities[$element1Id] <= $this->priorities[$element2Id];
        });

        return $elements;
    }
1035633
protected function getMenuItem(EntityInterface $menu, array $item, int $order = 0): array
    {
        if (empty($item)) {
            return [];
        }

        $label = $item['label'];
        $icon = $item['icon'];
        $type = $item['type'];

        $children = !empty($item['children']) ? $item['children'] : [];

        if (!empty($children)) {
            $count = 0;
            foreach ($children as $key => $child) {
                $children[$key] = $this->getMenuItem($menu, $child, ++$count);
            }
        }

        if (static::TYPE_MODULE === $type) {
            $item = $this->getMenuItemsFromEvent($menu->get('name'), [$item['url']]);
            reset($item);
            $item = current($item);
        }

        if (!empty($children)) {
            $item['children'] = $children;
        }

        if (empty($item)) {
            return [];
        }

        if (static::TYPE_MODULE === $type) {
            $item['label'] = $label;
            $item['icon'] = $icon;
        }

        $item['order'] = $order;

        return $item;
    }
334139
public function searchMenuEntryForKey($menuEntries, $key)
    {
        foreach ($menuEntries as $menuEntry) {
            if ($menuEntry->getKey() === $key) {
                return $menuEntry;
            } 
            
            if ($menuEntry->hasChildren()) {
                $result = $this->searchMenuEntryForKey($menuEntry->getChildren(), $key);
                
                if ($result !== false) {
                    return $result;
                }
            }
        }
        
        return false;
    }
433775
public static function getMenuLinks($menuSlug)
    {
        // Set active MenuLinks
        MenuLink::setActiveIDs(true);

        $menuData = self::findBySlug($menuSlug);
        $menuLinks = MenuLink::where('menuID', $menuData->menuID)->orderBy('order')->get();

        if($menuLinks) {
            return MenuLink::children($menuLinks);
        }
    }
1171588
protected function _getCurrentMenuElement(array $options = [], $level = 1)
    {
        if ($level > 1) {
            $levelElement = $this->_getLevelElement($options, $level);
            if ($this->_View->elementExists($levelElement)) {
                return $levelElement;
            }

            return $options['childMenuAttr']['element'];
        }

        return $options['menuAttr']['element'];
    }
1288653
public function getMenuItems(): array
    {
        usort($this->menuItems, function ($a, $b) {
            return $a->getOrder() > $b->getOrder();
        });

        return $this->menuItems;
    }
587077
public function get($code)
    {
        $result = null;
        $this->hook->attach('language.get.before', $code, $result, $this);

        if (isset($result)) {
            return (array) $result;
        }

        $list = $this->getList();
        $result = isset($list[$code]) ? $list[$code] : array();

        $this->hook->attach('language.get.after', $code, $result, $this);
        return (array) $result;
    }
728726
private function addElementByMenuCode(
        $element,
        $menuCode
    ) {
        if (!isset($this->elementsStoredByMenuCode[$menuCode])) {
            $this->elementsStoredByMenuCode[$menuCode] = [];
        }

        $elementId = spl_object_hash($element);
        $this->elementsStoredByMenuCode[$menuCode][$elementId] = $element;

        return $this;
    }
841416
protected function UserGetGroupIdByCode($code)
    {
        $rsGroups = CGroup::GetList(($by = 'c_sort'), ($order = 'desc'), [
            'STRING_ID' => $code,
        ]);
        if ($ob = $rsGroups->Fetch()) {
            return $ob['ID'];
        } else {
            return null;
        }
    }
1013816
public function stageChildren($showAll = false) {
		if ($this->Title != 'Content Root' && $this->source) {
			$children = new ArrayList();
			$item = new ExternalContentItem($this->source, $this->Title . '1');
			$item->Title = $this->Title . '1';
			$item->MenuTitle = $item->Title;

			$children->push($item);
			return $children;
		}
	}
274979
public function getChildren(MenuItem $parent = null)
    {
        if ($parent === null) {
            return $this->getTopChildren();
        }
        /* @var $request Request */
        $request = $this->container->get('request_stack')->getCurrentRequest();
        $result = array();
        foreach ($this->getAdaptors() as $menuAdaptor) {
            $menuAdaptor->adaptChildren($this, $result, $parent, $request);
        }

        return $result;
    }
143138
public function applyChange(
        MenuInterface $menu,
        $stage
    ) {
        $this->applyModifiersToMenuNodes(
            $menu->getSubnodes(),
            $menu->getCode(),
            $stage
        );

        return $this;
    }
664236
public function findByCode($code)
    {
        foreach ($this->sections as $section) {
            if ($section->getCharCodeFrom() <= $code && $section->getCharCodeTo() >= $code) {
                return $section;
            }
        }

        return null;
    }
593336
public function listSideMenuItems($owner = null, $code = null)
    {
        $activeItem = null;

        if ($owner !== null && $code !== null) {
            $activeItem = @$this->items[$this->makeItemKey($owner, $code)];
        } else {
            foreach ($this->listMainMenuItems() as $item) {
                if ($this->isMainMenuItemActive($item)) {
                    $activeItem = $item;
                    break;
                }
            }
        }

        if (!$activeItem) {
            return [];
        }

        $items = $activeItem->sideMenu;

        foreach ($items as $item) {
            if ($item->counter !== null && is_callable($item->counter)) {
                $item->counter = call_user_func($item->counter, $item);
            }
        }

        return $items;
    }
725664
private function applyModifiersToMenuNodes(
        Collection $menuNodes,
        $menuCode,
        $stage
    ) {
        $menuNodes->map(function (NodeInterface $menuNode) use ($menuCode, $stage) {

            $this->applyModifiersToMenuNodes(
                $menuNode->getSubnodes(),
                $menuCode,
                $stage
            );

            $menuModifiers = $this->getElementsByMenuCodeAndStage(
                $menuCode,
                $stage
            );

            /**
             * @var MenuModifierInterface $menuModifier
             */
            foreach ($menuModifiers as $menuModifier) {
                $menuModifier->modify($menuNode);
            }
        });

        return $this;
    }
1113858
public static function get_menu_item($code)
    {
        $menuItems = self::get_menu_items();
        return (isset($menuItems[$code])) ? $menuItems[$code] : false;
    }
800668
public function getTopChildren()
    {
        if (is_null($this->topMenuItems)) {
            /* @var $request Request */
            $request = $this->container->get('request_stack')->getCurrentRequest();
            $this->topMenuItems = array();
            foreach ($this->getAdaptors() as $menuAdaptor) {
                $menuAdaptor->adaptChildren($this, $this->topMenuItems, null, $request);
            }
        }

        return $this->topMenuItems;
    }