/** * Returns the main menu of the CMS. This is also used by init() * to work out which sections the user has access to. * * @param Boolean * @return SS_List */ public function MainMenu($cached = true) { if (!isset($this->_cache_MainMenu) || !$cached) { // Don't accidentally return a menu if you're not logged in - it's used to determine access. if (!Member::currentUser()) { return new ArrayList(); } // Encode into DO set $menu = new ArrayList(); $menuItems = CMSMenu::get_viewable_menu_items(); // extra styling for custom menu-icons $menuIconStyling = ''; if ($menuItems) { foreach ($menuItems as $code => $menuItem) { // alternate permission checks (in addition to LeftAndMain->canView()) if (isset($menuItem->controller) && $this->hasMethod('alternateMenuDisplayCheck') && !$this->alternateMenuDisplayCheck($menuItem->controller)) { continue; } $linkingmode = "link"; if ($menuItem->controller && get_class($this) == $menuItem->controller) { $linkingmode = "current"; } else { if (strpos($this->Link(), $menuItem->url) !== false) { if ($this->Link() == $menuItem->url) { $linkingmode = "current"; // default menu is the one with a blank {@link url_segment} } else { if (singleton($menuItem->controller)->stat('url_segment') == '') { if ($this->Link() == $this->stat('url_base') . '/') { $linkingmode = "current"; } } else { $linkingmode = "current"; } } } } // already set in CMSMenu::populate_menu(), but from a static pre-controller // context, so doesn't respect the current user locale in _t() calls - as a workaround, // we simply call LeftAndMain::menu_title_for_class() again // if we're dealing with a controller if ($menuItem->controller) { $defaultTitle = LeftAndMain::menu_title_for_class($menuItem->controller); $title = _t("{$menuItem->controller}.MENUTITLE", $defaultTitle); } else { $title = $menuItem->title; } // Provide styling for custom $menu-icon. Done here instead of in // CMSMenu::populate_menu(), because the icon is part of // the CMS right pane for the specified class as well... if ($menuItem->controller) { $menuIcon = LeftAndMain::menu_icon_for_class($menuItem->controller); if (!empty($menuIcon)) { $menuIconStyling .= $menuIcon; } } $menu->push(new ArrayData(array("MenuItem" => $menuItem, "Title" => Convert::raw2xml($title), "Code" => DBField::create_field('Text', $code), "Link" => $menuItem->url, "LinkingMode" => $linkingmode))); } } if ($menuIconStyling) { Requirements::customCSS($menuIconStyling); } $this->_cache_MainMenu = $menu; } return $this->_cache_MainMenu; }