Version: current

# Class CMSMenu

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

  SS_Object
  CMSMenu implements IteratorAggregate, i18nEntityProvider

Package: cms\content
Used by: ``CMSMain::init()``
Used by: ``CommentAdmin::init()``
Used by: ``CustomMenuAdmin::init()``
Used by: ``FaqAdmin::init()``
Used by: ``LeftAndMain::init()``
Used by: ``NewsletterAdmin::init()``
Used by: ``ReportAdmin::init()``
Used by: ``SecurityAdmin::init()``
Used by: ``WidgetAdmin::init()``
Located at cms/code/CMSMenu.php

## Methods summary

`public static` | # `populate_menu( )` Generate CMS main menu items by collecting valid subclasses of `LeftAndMain` Generate CMS main menu items by collecting valid subclasses of `LeftAndMain`
`public static` | # `add_director_rules( )` Add Director rules for all of the CMS controllers. Add Director rules for all of the CMS controllers.
`public static The` | # `add_controller( string $controllerClass )` Add a LeftAndMain controller to the CMS menu. Add a LeftAndMain controller to the CMS menu. #### Parameters $controllerClass string $controllerClass The class name of the controller #### Returns `The` result of the operation
`protected static` | # `menuitem_for_controller( mixed $controllerClass )` Return a CMSMenuItem to add the given controller to the CMSMenu Return a CMSMenuItem to add the given controller to the CMSMenu
`protected static` | # `add_director_rule_for_controller( mixed $controllerClass )` Add the appropriate Director rules for the given controller. Add the appropriate Director rules for the given controller.
`public static boolean` | # `add_link( string $code, string $menuTitle, string $url, integer $priority = -1 )` Add an arbitrary URL to the CMS menu. Add an arbitrary URL to the CMS menu. #### Parameters $code string $code A unique identifier (used to create a CSS ID and as it's key in $menu_items $menuTitle string $menuTitle The link's title in the CMS menu $url string $url The url of the link $priority integer $priority The menu priority (sorting order) of the menu item. Higher priorities will be further left. #### Returns `boolean` The result of the operation.
`public static boolean` | # `add_menu_item( string $code, string $menuTitle, string $url, string $controllerClass = null, mixed $priority = -1 )` Add a navigation item to the main administration menu showing in the top bar. Add a navigation item to the main administration menu showing in the top bar. uses CMSMenu::$menu_items #### Parameters $code string $code Unique identifier for this menu item (e.g. used by `CMSMenu::replace_menu_item()` and `CMSMenu::remove_menu_item()`. Also used as a CSS-class for icon customization. $menuTitle string $menuTitle Localized title showing in the menu bar $url string $url A relative URL that will be linked in the menu bar. $controllerClass 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. $priority #### Returns `boolean` Success
`public static array` | # `get_menu_item( string $code )` Get a single menu item by its code value. Get a single menu item by its code value. #### Parameters $code string $code #### Returns `array` array
`public static array` | # `get_menu_items( )` Get all menu entries. Get all menu entries. #### Returns `array` array
`public static array` | # `get_viewable_menu_items( `Member` $member = null )` Get all menu items that the passed member can view. Defaults to `Member::currentUser()`. Get all menu items that the passed member can view. Defaults to `Member::currentUser()`. #### Parameters $member Member $member #### Returns `array` array
`public static` | # `remove_menu_item( string $code )` Removes an existing item from the menu. Removes an existing item from the menu. #### Parameters $code string $code Unique identifier for this menu item
`public static` | # `clear_menu( )` Clears the entire menu Clears the entire menu
`public static boolean` | # `replace_menu_item( string $code, string $menuTitle, string $url, string $controllerClass = null, mixed $priority = -1 )` Replace a navigation item to the main administration menu showing in the top bar. Replace a navigation item to the main administration menu showing in the top bar. #### Parameters $code string $code Unique identifier for this menu item (e.g. used by `CMSMenu::replace_menu_item()` and `CMSMenu::remove_menu_item()`. Also used as a CSS-class for icon customization. $menuTitle string $menuTitle Localized title showing in the menu bar $url string $url A relative URL that will be linked in the menu bar. Make sure to add a matching route via `Director::addRules()` to this url. $controllerClass 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. $priority #### Returns `boolean` Success
`protected static` | # `add_menu_item_obj( mixed $code, mixed $cmsMenuItem )` Add a previously built menuitem object to the menu Add a previously built menuitem object to the menu
`public static array` | # `get_cms_classes( string $root = 'LeftAndMain', boolean $recursive = true )` A utility funciton to retrieve subclasses of a given class that are instantiable (ie, not abstract) and have a valid menu title. A utility funciton to retrieve subclasses of a given class that are instantiable (ie, not abstract) and have a valid menu title. #### Parameters $root string $root The root class to begin finding subclasses $recursive boolean $recursive Look for subclasses recursively? #### Returns `array` Valid, unique subclasses
`public` | # `getIterator( )` IteratorAggregate Interface Method. Iterates over the menu items. IteratorAggregate Interface Method. Iterates over the menu items. #### Implementation of `IteratorAggregate::getIterator()`
`public array` | # `provideI18nEntities( )` Provide menu titles to the i18n entity provider Provide menu titles to the i18n entity provider #### Returns `array` All entites in an associative array, with entity name as the key, and a numerical array of pseudo-arguments for _t() as a value. #### Implementation of `i18nEntityProvider::provideI18nEntities()`

### Magic methods summary

## Properties summary

`protected static array` | $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' => new CMSMenuItem(...) ) - array('type' => 'remove', 'code' => 'codename' ) 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' => new CMSMenuItem(...) ) - array('type' => 'remove', 'code' => 'codename' )
`protected static boolean` | $menu_is_cleared | # Set to true if clear_menu() is called, to indicate that the default menu shouldn't be included Set to true if clear_menu() is called, to indicate that the default menu shouldn't be included

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -