/** * Gets a list of url_pattern => controller k/v pairs for each LeftAndMain derived controller */ public static function rules() { if (self::$_rules === null) { self::$_rules = array(); // Map over the array calling add_rule_for_controller on each $classes = CMSMenu::get_cms_classes(null, true, CMSMenu::URL_PRIORITY); array_map(array(__CLASS__, 'add_rule_for_controller'), $classes); } return self::$_rules; }
/** * Clear menu to default state as per LeftAndMain::init() */ protected function resetMenu() { CMSMenu::clear_menu(); CMSMenu::populate_menu(); CMSMenu::add_link('Help', _t('LeftAndMain.HELP', 'Help', 'Menu title'), LeftAndMain::config()->help_link, -2, array('target' => '_blank')); }
public function testAdvancedMenuHandling() { // Populate from CMS Classes, check for existance of SecurityAdmin CMSMenu::clear_menu(); CMSMenu::populate_menu(); $menuItem = CMSMenu::get_menu_item('SilverStripe-Admin-SecurityAdmin'); $this->assertInstanceOf('SilverStripe\\Admin\\CMSMenuItem', $menuItem, 'SecurityAdmin menu item exists'); $this->assertContains($menuItem->url, SecurityAdmin::singleton()->Link(), 'Menu item has the correct link'); $this->assertEquals($menuItem->controller, 'SilverStripe\\Admin\\SecurityAdmin', 'Menu item has the correct controller class'); $this->assertEquals($menuItem->priority, SecurityAdmin::singleton()->stat('menu_priority'), 'Menu item has the correct priority'); // Check that menu order is correct by priority // Note this will break if populate_menu includes normal links (ie, as not controller) $menuItems = CMSMenu::get_menu_items(); $priority = 9999; // ok, *could* be set larger, but shouldn't need to be! foreach ($menuItems as $menuItem) { $this->assertEquals($menuItem->priority, singleton($menuItem->controller)->stat('menu_priority'), "Menu item {$menuItem->title} has the correct priority"); $this->assertLessThanOrEqual($priority, $menuItem->priority, 'Menu item is of lower or equal priority'); } }
/** * Returns the main menu of the CMS. This is also used by init() * to work out which sections the user has access to. * * @param bool $cached * @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) { /** @var CMSMenuItem $menuItem */ 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() == AdminRootController::admin_url()) { $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() again // if we're dealing with a controller if ($menuItem->controller) { $title = LeftAndMain::menu_title($menuItem->controller); } 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, "AttributesHTML" => $menuItem->getAttributesHTML(), "Title" => Convert::raw2xml($title), "Code" => $code, "Icon" => strtolower($code), "Link" => $menuItem->url, "LinkingMode" => $linkingmode))); } } if ($menuIconStyling) { Requirements::customCSS($menuIconStyling); } $this->_cache_MainMenu = $menu; } return $this->_cache_MainMenu; }
<?php use SilverStripe\Admin\CMSMenu; use SilverStripe\Forms\HTMLEditor\TinyMCEConfig; // Default CMS HTMLEditorConfig TinyMCEConfig::get('cms')->setOptions(array('friendly_name' => 'Default CMS', 'priority' => '50', 'body_class' => 'typography', 'contextmenu' => "sslink ssmedia inserttable | cell row column deletetable", 'use_native_selects' => false, 'valid_elements' => "@[id|class|style|title],a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title" . "|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class]," . "-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align|data*]," . "-sub[class],-sup[class],-blockquote[dir|class],-cite[dir|class|id|title]," . "-table[cellspacing|cellpadding|width|height|class|align|summary|dir|id|style]," . "-tr[id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style]," . "tbody[id|class|style],thead[id|class|style],tfoot[id|class|style]," . "#td[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style]," . "-th[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],caption[id|dir|class]," . "-div[id|dir|class|align|style],-span[class|align|style],-pre[class|align],address[class|align]," . "-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style]," . "-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class]," . "dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir]", 'extended_valid_elements' => "img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name" . "|usemap|data*],iframe[src|name|width|height|align|frameborder|marginwidth|marginheight|scrolling]," . "object[width|height|data|type],param[name|value],map[class|name|id],area[shape|coords|href|target|alt]")); TinyMCEConfig::get('cms')->enablePlugins(array('contextmenu' => null, 'image' => null, 'ssbuttons' => FRAMEWORK_ADMIN_DIR . '/client/dist/js/TinyMCE_SSPlugin.js')); CMSMenu::remove_menu_class('SilverStripe\\Admin\\CMSProfileController');