class CMSMenu implements IteratorAggregate, i18nEntityProvider

The object manages the main CMS menu. See {@link LeftAndMain::init()} for example usage.

The menu will be automatically populated with menu items for subclasses of {@link LeftAndMain}. That is, for each class in the CMS that creates an administration panel, a CMS menu item will be created. The default configuration will also include a 'help' link to the SilverStripe user documentation.

Additional CMSMenu items can be added through {@link LeftAndMainExtension::init()} extensions added to {@link LeftAndMain}.

Constants

MENU_PRIORITY

Sort by menu priority, highest to lowest

URL_PRIORITY

Sort by url priority, highest to lowest

Methods

static 
populate_menu()

Generate CMS main menu items by collecting valid subclasses of {@link LeftAndMain}

static 
add_controller(string $controllerClass)

Add a LeftAndMain controller to the CMS menu.

static boolean
add_link(string $code, string $menuTitle, string $url, integer $priority = -1, array $attributes = null, string $iconClass = null)

Add an arbitrary URL to the CMS menu.

static bool
add_menu_item(string $code, string $menuTitle, string $url, string $controllerClass = null, int $priority = -1, array $attributes = null, string $iconClass = null)

Add a navigation item to the main administration menu showing in the top bar.

static array
get_menu_item(string $code)

Get a single menu item by its code value.

static string
get_menu_code(string $cmsClass)

Get menu code for class

static array
get_menu_items()

Get all menu entries.

static array
get_viewable_menu_items(Member $member = null)

Get all menu items that the passed member can view.

static 
remove_menu_item(string $code)

Removes an existing item from the menu.

static 
remove_menu_class(string $className)

Remove menu item by class name.

static 
clear_menu()

Clears the entire menu

static bool
replace_menu_item(string $code, string $menuTitle, string $url, string $controllerClass = null, int $priority = -1, array $attributes = null, string $iconClass = null)

Replace a navigation item to the main administration menu showing in the top bar.

static array
get_cms_classes(string $root = null, boolean $recursive = true, string $sort = self::MENU_PRIORITY)

A utility funciton to retrieve subclasses of a given class that are instantiable (ie, not abstract) and have a valid menu title.

getIterator()

IteratorAggregate Interface Method. Iterates over the menu items.

array
provideI18nEntities()

Provide menu titles to the i18n entity provider

Details

at line 63
static populate_menu()

Generate CMS main menu items by collecting valid subclasses of {@link LeftAndMain}

at line 75
static add_controller(string $controllerClass)

Add a LeftAndMain controller to the CMS menu.

Parameters

string $controllerClass The class name of the controller

Add an arbitrary URL to the CMS menu.

Parameters

string $code A unique identifier (used to create a CSS ID and its key in {@link $menu_items})
string $menuTitle The link's title in the CMS menu
string $url The url of the link
integer $priority The menu priority (sorting order) of the menu item. Higher priorities will be further left.
array $attributes an array of attributes to include on the link.
string $iconClass

Return Value

boolean The result of the operation.

at line 148
static bool add_menu_item(string $code, string $menuTitle, string $url, string $controllerClass = null, int $priority = -1, array $attributes = null, string $iconClass = null)

Add a navigation item to the main administration menu showing in the top bar.

uses {@link CMSMenu::$menu_items}

Parameters

string $code Unique identifier for this menu item (e.g. used by {@link replace_menu_item()} and {@link remove_menu_item}. Also used as a CSS-class for icon customization.
string $menuTitle Localized title showing in the menu bar
string $url A relative URL that will be linked in the menu bar.
string $controllerClass The controller class for this menu, used to check permisssions. If blank, it's assumed that this is public, and always shown to users who have the rights to access some other part of the admin area.
int $priority
array $attributes an array of attributes to include on the link.
string $iconClass

Return Value

bool Success

at line 179
static array get_menu_item(string $code)

Get a single menu item by its code value.

Parameters

string $code

Return Value

array

at line 191
static string get_menu_code(string $cmsClass)

Get menu code for class

Parameters

string $cmsClass Controller class name

Return Value

string

at line 201
static array get_menu_items()

Get all menu entries.

Return Value

array

at line 252
static array get_viewable_menu_items(Member $member = null)

Get all menu items that the passed member can view.

Defaults to {@link Security::getCurrentUser()}.

Parameters

Member $member

Return Value

array

at line 288
static remove_menu_item(string $code)

Removes an existing item from the menu.

Parameters

string $code Unique identifier for this menu item

at line 298
static remove_menu_class(string $className)

Remove menu item by class name.

Parameters

string $className Name of class

at line 307
static clear_menu()

Clears the entire menu

at line 330
static bool replace_menu_item(string $code, string $menuTitle, string $url, string $controllerClass = null, int $priority = -1, array $attributes = null, string $iconClass = null)

Replace a navigation item to the main administration menu showing in the top bar.

Parameters

string $code Unique identifier for this menu item (e.g. used by {@link replace_menu_item()} and {@link remove_menu_item}. Also used as a CSS-class for icon customization.
string $menuTitle Localized title showing in the menu bar
string $url A relative URL that will be linked in the menu bar. Make sure to add a matching route via {@link Director::$rules} to this url.
string $controllerClass The controller class for this menu, used to check permisssions. If blank, it's assumed that this is public, and always shown to users who have the rights to access some other part of the admin area.
int $priority
array $attributes an array of attributes to include on the link.
string $iconClass

Return Value

bool Success

at line 379
static array get_cms_classes(string $root = null, boolean $recursive = true, string $sort = self::MENU_PRIORITY)

A utility funciton to retrieve subclasses of a given class that are instantiable (ie, not abstract) and have a valid menu title.

Sorted by url_priority config.

Parameters

string $root The root class to begin finding subclasses
boolean $recursive Look for subclasses recursively?
string $sort Name of config on which to sort. Can be 'menu_priority' or 'url_priority'

Return Value

array Valid, unique subclasses

at line 419
getIterator()

IteratorAggregate Interface Method. Iterates over the menu items.

at line 427
array provideI18nEntities()

Provide menu titles to the i18n entity provider

Return Value

array Map of keys to default values, which are strings in the default case, and array-form for pluralisations.