Skip to content

Commit 0f87e8e

Browse files
author
Andy McCormick
committed
added sidebar updates
1 parent 80a896e commit 0f87e8e

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

docs/development/modules.md

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ This would add a breadcrumb that would look like `Add-Ons -> [Add-On Name] -> Se
112112
### Sidebar
113113
If your add-on has multiple Control Panel pages, a sidebar can be incredibly helpful for your users to easily navigate between pages. Sidebars can either be generated automatically or manually.
114114

115-
#### Automatically Generate Your Sidebar
116-
We can use the `make:sidebar` CLI command to generate a sidebar file for us.
115+
Both of these options start with generating your sidebar class using the CLI.
116+
117+
We use the `make:sidebar` CLI command to generate a sidebar file for us.
117118

118119
```
119120
$ php system/ee/eecli.php make:sidebar
@@ -156,7 +157,8 @@ class Sidebar extends AbstractSidebar
156157
}
157158
```
158159

159-
That's it! Our `Sidebar` class will scan our `Mcp` folder for all available Control Panel routes and automatically create respective entries in our sidebar. There's no need to add the sidebar to your Control Panel page as it will automatically be added when the page is rendered.
160+
#### Automatically Generate Your Sidebar
161+
If you'd like to have your sidebar automatically generated then that's it! The `Sidebar` class will scan our `Mcp` folder for all available Control Panel routes and automatically create respective entries in our sidebar. There's no need to add the sidebar to your Control Panel page as it will automatically be added when the page is rendered.
160162

161163
Example:
162164

@@ -178,14 +180,40 @@ Would produce a sidebar in the Control Panel like this:
178180
![control panel sidebar](_images/addon_sidebar_start.png)
179181

180182

181-
You can take this a step further by adjusting the following properties in your `Mcp` files to adjust how sidebar items are displayed:
182-
- **`protected $sidebar_title (string)`** - By default the sidebar link text is based on your route's name. This property will overwrite the text displayed for this route.
183-
- **`protected $sidebar_icon (string)`** - The Font Awesome icon you wish to display next to the sidebar link for this route.
184-
- **`protected $sidebar_is_folder (bool)`** -
185-
- **`protected $sidebar_is_list (bool)`** -
186-
- **`protected $exclude_from_sidebar (bool)`** - Exclude this route from the sidebar.
187-
- **`protected $sidebar_divider_before (bool)`** - Inserts a divider in the sidebar before
188-
- **`protected $sidebar_divider_after (bool)`** -
183+
You can take this a step further by adjusting the following properties in your Control Panel routes (`Mcp/[route_name].php`) to adjust how sidebar items are displayed:
184+
##### `protected $sidebar_title (string)`
185+
By default the sidebar link text is based on your route's name. This property will overwrite the text displayed for this route.
186+
187+
##### `protected $sidebar_icon (string)`
188+
The Font Awesome icon you wish to display next to the sidebar link for this route.
189+
190+
##### `protected $sidebar_priority (int)`
191+
Give this route a higher priority in the sidebar. Higher priority items will appear first in the sidebar.
192+
193+
##### `protected $exclude_from_sidebar (bool)`
194+
Exclude this route from the sidebar.
195+
196+
##### `protected $sidebar_divider_before (bool)`
197+
Inserts a divider in the sidebar before the link to this route.
198+
199+
##### `protected $sidebar_divider_after (bool)`
200+
Inserts a divider in the sidebar after the link to this route.
201+
202+
203+
You can even modify the generated sidebar in the `process()` method of your `Mcp/Sidebar.php` file by utilizing the [`CP/Sidebar Service`](development/services/sidebar.md).
204+
205+
#### Manually Generate Your Sidebar
206+
207+
We will set the `$automatic` property in our `Mcp/Sidebar.php` file to `false`.
208+
209+
```
210+
public $automatic = false;
211+
```
212+
213+
This tells our Sidebar class not to automatically create any sidebars.
214+
215+
From here you can utilize utilize the [`CP/Sidebar Service`](development/services/sidebar.md) in the `process()` method of our Sidebar class to manually create your sidebar and all related items.
216+
189217

190218
### Toolbar
191219

docs/development/services/sidebar.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ lang: php
1515

1616
[TOC]
1717

18+
## Automatically Created Sidebars
19+
If you are automatically generating a sidebar in your add-on you can use either of these methods to customize the sidebar further:
20+
- Modify the sidebar on every page load in the in the `process()` method of your `Mcp/Sidebar.php` file. The sidebar object is available using `$this->getSidebar()` You can also loop through each sidebar item with $this->getItems()`
21+
- Modify the sidebar only when a specific route is loaded by accessing the sidebar instance in the `process()` function of the route file (`Mcp/[route_name].php`).You can modify the sidebar item connected to the current route by using `$this->getCurrentSidebarItem()` with the [BasicItem Methods](#basicitem-methods) listed below. You can also use `$this->getSidebar()` to get the entire sidebar instance.
22+
23+
1824
## Simple Example
1925

2026
```php

0 commit comments

Comments
 (0)