class CMSMenu implements IteratorAggregate, i18nEntityProvider (View source)

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

The menu will be automatically populated with menu items for subclasses of 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 LeftAndMainExtension::init() extensions added to LeftAndMain.

Constants

MENU_PRIORITY

Sort by menu priority, highest to lowest

URL_PRIORITY

Sort by url priority, highest to lowest

Properties

protected static $menu_item_changes

An array of changes to be made to the menu items, in the order that the changes should be applied. Each item is a map in one of the two forms:

  • array('type' => 'add', 'item' => CMSMenuItem::create(...) )
  • array('type' => 'remove', 'code' => 'codename' )
protected static $menu_is_cleared

Set to true if clear_menu() is called, to indicate that the default menu shouldn't be included

Methods

public static 
populate_menu()

Generate CMS main menu items by collecting valid subclasses of LeftAndMain

public static 
add_controller(string $controllerClass)

Add a LeftAndMain controller to the CMS menu.

protected static 
menuitem_for_controller(string $controllerClass)

Return a CMSMenuItem to add the given controller to the CMSMenu

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

Add an arbitrary URL to the CMS menu.

public 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.

public static 
array
get_menu_item(string $code)

Get a single menu item by its code value.

public static 
string
get_menu_code(string $cmsClass)

Get menu code for class

public static 
array
get_menu_items()

Get all menu entries.

public static 
get_viewable_menu_items(Member $member = null)

Get all menu items that the passed member can view.

public static 
remove_menu_item(string $code)

Removes an existing item from the menu.

public static 
remove_menu_class(string $className)

Remove menu item by class name.

public static 
clear_menu()

Clears the entire menu

public 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.

protected static 
add_menu_item_obj(string $code, CMSMenuItem $cmsMenuItem)

Add a previously built menu item object to the menu

public static 
array
get_cms_classes(string $root = null, bool $recursive = true, string $sort = CMSMenu::MENU_PRIORITY)

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

public
getIterator()

IteratorAggregate Interface Method. Iterates over the menu items.

public
array
provideI18nEntities()

Provide menu titles to the i18n entity provider

Details

static populate_menu()

Generate CMS main menu items by collecting valid subclasses of LeftAndMain

static add_controller(string $controllerClass)

Add a LeftAndMain controller to the CMS menu.

Parameters

string $controllerClass

The class name of the controller

static protected CMSMenuItem menuitem_for_controller(string $controllerClass)

Return a CMSMenuItem to add the given controller to the CMSMenu

Parameters

string $controllerClass

Return Value

CMSMenuItem

Add an arbitrary URL to the CMS menu.

Parameters

string $code

A unique identifier (used to create a CSS ID and its key in $menu_items)

string $menuTitle

The link's title in the CMS menu

string $url

The url of the link

int $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

bool

The result of the operation.

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 CMSMenu::$menu_items

Parameters

string $code

Unique identifier for this menu item (e.g. used by replace_menu_item() and 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

static array get_menu_item(string $code)

Get a single menu item by its code value.

Parameters

string $code

Return Value

array

static string get_menu_code(string $cmsClass)

Get menu code for class

Parameters

string $cmsClass

Controller class name

Return Value

string

static array get_menu_items()

Get all menu entries.

Return Value

array

static CMSMenuItem[] get_viewable_menu_items(Member $member = null)

Get all menu items that the passed member can view.

Defaults to Security::getCurrentUser().

Parameters

Member $member

Return Value

CMSMenuItem[]

static remove_menu_item(string $code)

Removes an existing item from the menu.

Parameters

string $code

Unique identifier for this menu item

static remove_menu_class(string $className)

Remove menu item by class name.

Parameters

string $className

Name of class

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.

Parameters

string $code

Unique identifier for this menu item (e.g. used by replace_menu_item() and 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 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

static protected add_menu_item_obj(string $code, CMSMenuItem $cmsMenuItem)

Add a previously built menu item object to the menu

Parameters

string $code
CMSMenuItem $cmsMenuItem

static array get_cms_classes(string $root = null, bool $recursive = true, string $sort = CMSMenu::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

bool $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

Traversable getIterator()

IteratorAggregate Interface Method. Iterates over the menu items.

Return Value

Traversable

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.