/** * Renders a menu for the top level of the page heirarchy. * * Pages are only listed if they are set to be visible in menus; are * currently published and are viewable by the current user. * * The current top-level (root) page is passed to the view as "current". * * @return \Message\Cog\HTTP\Response */ public function topLevel() { $loader = $this->get('cms.page.loader')->includeDeleted(false); $current = isset($this->_services['cms.page.current']) ? $loader->getRoot($this->get('cms.page.current')) : null; $event = new BuildPageMenuEvent('main'); $event->addPages($loader->getTopLevel()); $pages = $this->get('event.dispatcher')->dispatch(Events::FRONTEND_BUILD_MENU, $event)->getPages(); return $this->render('Message:Mothership:CMS::modules/menu', array('pages' => $pages, 'current' => $current)); }
/** * Filter out any `Page`s in an array that should not be shown in a menu. * * Pages are filtered out if they shouldn't be visible in menus; are not * published; or are not viewable by the current user. * * @param FrontendBuildMenuEvent $events Build menu event */ public function filterMenuItems(FrontendBuildMenuEvent $event) { $auth = $this->get('cms.page.authorisation'); foreach ($event->getPages() as $page) { if (!$page->visibilityMenu || !$auth->isPublished($page) || !$auth->isViewable($page)) { $event->remove($page); } } }