2019-11-18 05:58:33 +01:00
|
|
|
---
|
|
|
|
title: Customise the CMS Menu
|
|
|
|
summary: Make custom changes to the left hand menu in the CMS
|
|
|
|
---
|
2016-03-30 02:17:28 +02:00
|
|
|
# How to customise the CMS Menu
|
2012-08-19 14:14:41 +02:00
|
|
|
|
2015-07-15 16:36:33 +02:00
|
|
|
## Adding an administration panel
|
2012-08-19 14:14:41 +02:00
|
|
|
|
2017-07-03 03:22:12 +02:00
|
|
|
Every time you add a new extension of the [LeftAndMain](api:SilverStripe\Admin\LeftAndMain) class to the CMS,
|
2021-06-30 11:48:52 +02:00
|
|
|
Silverstripe CMS will automatically create a new [CMSMenuItem](api:SilverStripe\Admin\CMSMenuItem) for it
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2017-07-03 03:22:12 +02:00
|
|
|
The most popular extension of LeftAndMain is a [ModelAdmin](api:SilverStripe\Admin\ModelAdmin) class, so
|
2013-10-02 08:06:54 +02:00
|
|
|
for a more detailed introduction to creating new `ModelAdmin` interfaces, read
|
2015-02-28 01:09:15 +01:00
|
|
|
the [ModelAdmin reference](../modeladmin).
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2014-11-07 20:43:57 +01:00
|
|
|
In this document we'll take the `ProductAdmin` class used in the
|
2015-02-28 01:09:15 +01:00
|
|
|
[ModelAdmin reference](../modeladmin#setup) and so how we can change
|
2014-11-07 20:43:57 +01:00
|
|
|
the menu behaviour by using the `$menu_title` and `$menu_icon` statics to
|
2012-08-19 14:14:41 +02:00
|
|
|
provide a custom title and icon.
|
|
|
|
|
2013-10-02 08:06:54 +02:00
|
|
|
### Defining a Custom Icon
|
2012-08-19 14:14:41 +02:00
|
|
|
|
2021-06-30 11:48:52 +02:00
|
|
|
First we'll need a custom icon. For this purpose Silverstripe CMS uses 16x16
|
2014-11-07 20:43:57 +01:00
|
|
|
black-and-transparent PNG graphics. In this case we'll place the icon in
|
2018-06-25 00:39:53 +02:00
|
|
|
`app/images`, but you are free to use any location.
|
2012-08-19 14:14:41 +02:00
|
|
|
|
2017-08-03 02:51:32 +02:00
|
|
|
|
|
|
|
```php
|
2017-10-27 04:38:27 +02:00
|
|
|
use SilverStripe\Admin\ModelAdmin;
|
2017-08-05 00:45:24 +02:00
|
|
|
|
2018-09-19 06:50:24 +02:00
|
|
|
class ProductAdmin extends ModelAdmin
|
2017-10-27 04:38:27 +02:00
|
|
|
{
|
|
|
|
// ...
|
2018-06-25 00:39:53 +02:00
|
|
|
private static $menu_icon = 'app/images/product-icon.png';
|
2017-10-27 04:38:27 +02:00
|
|
|
}
|
2017-08-03 02:51:32 +02:00
|
|
|
```
|
2012-08-19 14:14:41 +02:00
|
|
|
|
2013-10-02 08:06:54 +02:00
|
|
|
### Defining a Custom Title
|
2012-08-19 14:14:41 +02:00
|
|
|
|
|
|
|
The title of menu entries is configured through the `$menu_title` static.
|
2014-11-07 20:43:57 +01:00
|
|
|
If its not defined, the CMS falls back to using the class name of the
|
2013-10-02 08:06:54 +02:00
|
|
|
controller, removing the "Admin" bit at the end.
|
2012-08-19 14:14:41 +02:00
|
|
|
|
2017-08-03 02:51:32 +02:00
|
|
|
|
|
|
|
```php
|
2017-10-27 04:38:27 +02:00
|
|
|
use SilverStripe\Admin\ModelAdmin;
|
2017-08-05 00:45:24 +02:00
|
|
|
|
2018-09-19 06:50:24 +02:00
|
|
|
class ProductAdmin extends ModelAdmin
|
2017-10-27 04:38:27 +02:00
|
|
|
{
|
|
|
|
// ...
|
|
|
|
private static $menu_title = 'My Custom Admin';
|
|
|
|
}
|
2017-08-03 02:51:32 +02:00
|
|
|
```
|
2014-11-07 20:43:57 +01:00
|
|
|
|
|
|
|
In order to localize the menu title in different languages, use the
|
|
|
|
`<classname>.MENUTITLE` entity name, which is automatically created when running
|
2013-10-02 08:06:54 +02:00
|
|
|
the i18n text collection.
|
|
|
|
|
2014-11-07 20:43:57 +01:00
|
|
|
For more information on language and translations, please refer to the
|
2016-01-14 11:59:53 +01:00
|
|
|
[i18n](/developer_guides/i18n) docs.
|
2013-10-02 08:06:54 +02:00
|
|
|
|
|
|
|
## Adding an external link to the menu
|
|
|
|
|
2014-11-07 20:43:57 +01:00
|
|
|
On top of your administration windows, the menu can also have external links
|
|
|
|
(e.g. to external reference). In this example, we're going to add a link to
|
2013-10-02 08:06:54 +02:00
|
|
|
Google to the menu.
|
|
|
|
|
2017-07-03 03:22:12 +02:00
|
|
|
First, we need to define a [LeftAndMainExtension](api:SilverStripe\Admin\LeftAndMainExtension) which will contain our
|
2013-10-02 08:06:54 +02:00
|
|
|
button configuration.
|
|
|
|
|
2017-08-03 02:51:32 +02:00
|
|
|
|
|
|
|
```php
|
2017-10-27 04:38:27 +02:00
|
|
|
use SilverStripe\Admin\CMSMenu;
|
|
|
|
use SilverStripe\Admin\LeftAndMainExtension;
|
2017-08-05 00:45:24 +02:00
|
|
|
|
2018-09-19 06:50:24 +02:00
|
|
|
class CustomLeftAndMain extends LeftAndMainExtension
|
2017-10-27 04:38:27 +02:00
|
|
|
{
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2018-09-19 06:50:24 +02:00
|
|
|
public function init()
|
2017-10-27 04:38:27 +02:00
|
|
|
{
|
|
|
|
// unique identifier for this item. Will have an ID of Menu-$ID
|
|
|
|
$id = 'LinkToGoogle';
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2017-10-27 04:38:27 +02:00
|
|
|
// your 'nice' title
|
|
|
|
$title = 'Google';
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2017-10-27 04:38:27 +02:00
|
|
|
// the link you want to item to go to
|
|
|
|
$link = 'http://google.com';
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2017-10-27 04:38:27 +02:00
|
|
|
// priority controls the ordering of the link in the stack. The
|
|
|
|
// lower the number, the lower in the list
|
|
|
|
$priority = -2;
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2017-10-27 04:38:27 +02:00
|
|
|
// Add your own attributes onto the link. In our case, we want to
|
|
|
|
// open the link in a new window (not the original)
|
|
|
|
$attributes = [
|
|
|
|
'target' => '_blank'
|
|
|
|
];
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2017-10-27 04:38:27 +02:00
|
|
|
CMSMenu::add_link($id, $title, $link, $priority, $attributes);
|
2017-08-07 05:11:17 +02:00
|
|
|
}
|
2017-10-27 04:38:27 +02:00
|
|
|
}
|
2017-08-03 02:51:32 +02:00
|
|
|
```
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2014-11-07 20:43:57 +01:00
|
|
|
To have the link appear, make sure you add the extension to the `LeftAndMain`
|
|
|
|
class. For more information about configuring extensions see the
|
2016-01-14 11:59:53 +01:00
|
|
|
[extensions reference](/developer_guides/extending/extensions).
|
2013-10-02 08:06:54 +02:00
|
|
|
|
|
|
|
|
2017-08-03 02:51:32 +02:00
|
|
|
```php
|
2017-10-27 04:38:27 +02:00
|
|
|
LeftAndMain::add_extension('CustomLeftAndMain')
|
2017-08-03 02:51:32 +02:00
|
|
|
```
|
2014-11-07 20:43:57 +01:00
|
|
|
|
2018-09-19 06:50:24 +02:00
|
|
|
## Customising the CMS help menu
|
|
|
|
|
|
|
|
The CMS help menu links in the south toolbar are configurable via your [configuration file](../../configuration).
|
|
|
|
You can edit, add or remove existing links as shown in the examples below:
|
|
|
|
|
|
|
|
```yml
|
|
|
|
# app/_config/config.yml
|
|
|
|
SilverStripe\Admin\LeftAndMain:
|
|
|
|
help_links:
|
|
|
|
# Edit an existing link
|
|
|
|
'CMS User help': 'https://example.com'
|
|
|
|
# Add a new link
|
|
|
|
'Additional link': 'https://example.org'
|
|
|
|
# Remove an existing link
|
|
|
|
'Feedback': ''
|
|
|
|
```
|
|
|
|
|
2018-11-18 23:06:47 +01:00
|
|
|
## Customising the CMS form actions
|
|
|
|
|
|
|
|
The `Previous`, `Next` and `Add` actions on the edit form are visible by default but can be hidden globally by adding the following `.yml` config:
|
|
|
|
|
|
|
|
```yml
|
|
|
|
SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest:
|
|
|
|
formActions:
|
|
|
|
showPagination: false
|
|
|
|
showAdd: false
|
|
|
|
```
|
|
|
|
|
|
|
|
You can also override this for a specific `GridField` instance when using the `GridFieldConfig_RecordEditor` constructor:
|
|
|
|
|
|
|
|
```php
|
|
|
|
$grid = new GridField(
|
|
|
|
"pages",
|
|
|
|
"All Pages",
|
|
|
|
SiteTree::get(),
|
|
|
|
GridFieldConfig_RecordEditor::create(null, false, false));
|
|
|
|
```
|
|
|
|
|
2012-08-19 14:14:41 +02:00
|
|
|
## Related
|
|
|
|
|
2015-02-28 01:09:15 +01:00
|
|
|
* [How to extend the CMS interface](extend_cms_interface)
|