/** * Get an array with menu items of a menu. * * @param string $name * @param string $lang * @return array */ public function getMenuItems($name, $lang) { /** @var MenuItem $menuRepo */ $arrayResult = $this->repository->getMenuItemsForLanguage($name, $lang); // Make sure the parent item is not offline $foundIds = array(); foreach ($arrayResult as $array) { $foundIds[] = $array['id']; } foreach ($arrayResult as $key => $array) { if (!is_null($array['parent']) && !in_array($array['parent']['id'], $foundIds)) { unset($arrayResult[$key]); } } return $arrayResult; }
/** * Get a html representation of a menu. * * @param string $name * @param string $lang * @param array $options * @return string */ public function getMenu($name, $lang, $options = array()) { /** @var MenuItem $menuRepo */ $arrayResult = $this->repository->getMenuItemsForLanguage($name, $lang); // Make sure the parent item is not offline $foundIds = array(); foreach ($arrayResult as $array) { $foundIds[] = $array['id']; } foreach ($arrayResult as $key => $array) { if (!is_null($array['parent']) && !in_array($array['parent']['id'], $foundIds)) { unset($arrayResult[$key]); } } // SET OPTIONS // Class for active item $activeClass = false; if (isset($options['activeClass'])) { $activeClass = $options['activeClass']; } $options = array_merge($this->getDefaultOptions($activeClass), $options); $html = $menuRepo->buildTree($arrayResult, $options); return $html; }