Skip to content

Commit 2aaa66f

Browse files
author
Andy McCormick
committed
updated MCP docs for new structure
1 parent 4cef658 commit 2aaa66f

File tree

2 files changed

+65
-59
lines changed

2 files changed

+65
-59
lines changed

docs/development/addon-development-overview.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ At this point, your add-on can't really do anything other than be installed. How
6464
Here's a list of functionality that can be added to your add-on and the corresponding CLI command if applicable:
6565

6666
- [Extension hooks (`make:extension-hook`)](development/extensions.md)
67-
- [Control Panel Pages (`make:mcp-route`)](development/modules.md)
67+
- [Control Panel Pages (`make:cp-route`)](development/modules.md)
6868
- [Actions (`make:action`)](development/actions.md)
6969
- [Fieldtypes (`make:fieldtype`)](development/fieldtypes/fieldtypes.md)
7070
- [CLI Commands (`make:command`)](cli/creating-a-command.md)
@@ -83,33 +83,33 @@ Below is the complete structure of an add-on that we'll call "Amazing Add-on". T
8383
```
8484
amazing_add_on
8585
┣ Commands
86-
CommandAnAmazingCommand.php
86+
CommandAnAmazingCommand.php
8787
┣ database
8888
┃ ┣ migrations
8989
┃ ┃ ┗ 2022_11_14_170449_amazing_migration.php
9090
┣ Extensions
9191
┃ ┣ TemplatePostParse.php
9292
┃ ┗ TypographyParseTypeEnd.php
93-
┣ Mcp
93+
┣ ControlPanel
94+
┃ ┣ Routes
95+
┃ ┃ ┣ Index.php
96+
┃ ┃ ┗ Page2.php
9497
┃ ┣ Sidebar.php
95-
┃ ┣ Index.php
96-
┃ ┗ Page2.php
97-
┣ Module
98-
┃ ┣ Actions
99-
┃ ┃ ┗ ExampleAction.php
100-
┃ ┗ Tags
101-
┃ ┃ ┗ ExampleTag.php
98+
┣ Actions
99+
┃ ┗ ExampleAction.php
100+
┣ Tags
101+
┃ ┗ ExampleTag.php
102102
┣ Model
103-
AmazingModel.php
103+
AmazingModel.php
104104
┣ language
105105
┃ ┣ english
106106
┃ ┃ ┣ amazing_add_on_lang.php
107107
┃ ┃ ┗ index.html
108108
┃ ┗ index.html
109109
┣ widgets
110-
AnAmazingWidget.php
110+
AnAmazingWidget.php
111111
┣ views
112-
┃ ┣ McpIndex.php
112+
┃ ┣ Index.php
113113
┃ ┗ Page2.php
114114
┣ addon.setup.php
115115
┣ ext.amazing_add_on.php
@@ -147,7 +147,7 @@ Reference [Adding Fieldtypes](development/fieldtypes/fieldtypes.md) for more inf
147147

148148
### The Mcp File (`mcp.[addon_name].php`)
149149
**class `Add_on_name_upd extends Mcp`**
150-
The Mcp file is used to route ExpressionEngine to our `Mcp` Folder, which contains logic for your Control Panel pages (settings or other pages you might want to add to the Control Panel for your users to interact with).
150+
The Mcp file is used to route ExpressionEngine to our `ControlPanel` Folder, which contains logic for your Control Panel pages (settings or other pages you might want to add to the Control Panel for your users to interact with).
151151
Reference [Adding Control Panel Pages](development/modules.md) for more information on adding Control Panel pages with your add-on.
152152

153153
### The Module File `mod.[addon_name].php`
@@ -173,16 +173,16 @@ When we tell the CLI that we want to create an extension, classes are automatica
173173

174174
TIP: Reference the [Extensions](development/extensions.md) section of the docs for more information on using extensions in your add-on.
175175

176-
### Actions - `/Module/Actions`
177-
The `Module/Actions` folder stores all the business logic for any actions that we are adding to ExpressionEngine with our add-on. Each action will have a separate file and corresponding class created based on information provided in the `$actions` array in the `upd` file.
176+
### Actions - `/Actions`
177+
The `/Actions` folder stores all the business logic for any actions that we are adding to ExpressionEngine with our add-on. Each action will have a separate file and corresponding class created based on information provided in the `$actions` array in the `upd` file.
178178
Reference [Adding Actions](development/actions.md) for more information on creating URL endpoints (actions) with your add-on.
179179

180-
### Control Panel Routes - `/Mcp`
181-
The `Mcp` folder contains all the Control Panel routes and we create for our add-on as well as our sidebar.
180+
### Control Panel Routes - `/ControlPanel`
181+
The `ControlPanel` folder contains all the Control Panel routes and we create for our add-on as well as our sidebar.
182182
Reference [Adding Control Panel Pages](development/modules.md) for more information on adding Control Panel routes and pages with your add-on.
183183

184-
### `Module/Tags`
185-
The `Module/Tags` folder stores all the business logic for any template tags we create with our add-on.
184+
### `/Tags`
185+
The `/Tags` folder stores all the business logic for any template tags we create with our add-on.
186186
Reference [Adding Template Tags](development/custom-template-tags.md) for more information on adding template tags with your add-on.
187187

188188
### `/views`

docs/development/modules.md

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,39 @@ lang: php
1616
[TOC=2-3]
1717

1818
## Overview
19-
If you have ever used some of the add-ons that ship with ExpressionEngine such as [Block and Allow](/add-ons/blocklist.md) or [Pro Search](/add-ons/pro-search/overview.md), you will notice those add-ons have settings and configuration pages associated with them in the Control Panel. You add this functionality to your add-on using Control Panel Routes, also known as `Mcp` files. Whenever you add a Control Panel Route to your add-on using the CLI, an `Mcp` and `views` folder is automatically created for you, opening the door to creating your own Control Panel settings and pages.
19+
If you have ever used some of the add-ons that ship with ExpressionEngine such as [Block and Allow](/add-ons/blocklist.md) or [Pro Search](/add-ons/pro-search/overview.md), you will notice those add-ons have settings and configuration pages associated with them in the Control Panel. You add this functionality to your add-on using Control Panel Routes.. Whenever you add a Control Panel Route to your add-on using the CLI, a `ControlPanel/Routes` and `views` folder is automatically created for you, opening the door to creating your own Control Panel settings and pages.
2020

2121
NOTE:**NOTE:** Control Pages are what is rendered in the browser when visiting your add-on in the Add-on Manager. Control Panel Routes are what we had to our add-on that tells ExpressionEngine to render the pages. Think of it as we add a route to create a page.
2222

2323
NOTE:Before adding a Control Panel route to your add-on, you need to already have an add-on in place. See [Building An Add-On: Getting Started](development/addon-development-overview.md#getting-started) for how to generate the starter files for your add-on.
2424

2525
## Creating An Amazing Control Panel Route
2626

27-
If your add-on doesn't already have the required `Mcp` and `views` files, you can add a route to your add-on using the `make:mcp-route` command in the CLI.
27+
If your add-on doesn't already have the required `ControlPanel/Routes` and `views` files, you can add a route to your add-on using the `make:cp-route` command in the CLI.
2828

2929
```
30-
$ php system/ee/eeclip.php make:mcp-route
30+
$ php system/ee/eeclip.php make:cp-route
31+
Let's create a control panel route!
32+
What is the route name? index
33+
What add-on is the route being added to? [amazing_add_on]: amazing_add_on
34+
Building control panel route.
35+
Control panel route created successfully!
3136
```
3237

3338
Follow the prompts to add the route to your add-on.
3439

35-
This will create an `mcp.[addon_name].php` file in your add-on along with a `Mcp` and `views` folder.
40+
This will create an `mcp.[addon_name].php` file in your add-on along with a `ControlPanel/Routes` and `views` folder.
3641

37-
Inside of the `Mcp` folder, you will see that the CLI has created your first control route with `Mcp/Index.php` and a corresponding view in you `views` folder. This page is accessible via The Add-On Manager -> [Add-On Name] or via the `/admin.php?/cp/addons/settings/[add-on-name]` URL.
42+
Inside of the `ControlPanel/Routes` folder, you will see that the CLI has created your first control route with `ControlPanel/Routes/Index.php` and a corresponding view in you `views` folder. This page is accessible via The Add-On Manager -> [Add-On Name] or via the `/admin.php?/cp/addons/settings/[add-on-name]` URL.
3843

3944

4045
## Anatomy Of A Control Panel Route
41-
When you first add a route to your add-on an `Mcp` folder along with an `Mcp/Index.php` starter file is created. The starter file will look something like this:
46+
When you first add a route to your add-on a `ControlPanel/Routes` folder along with an `ControlPanel/Routes/[RouteName].php` starter file is created. The starter file will look something like this:
4247

4348
```
4449
<?php
4550
46-
namespace ExpressionengineDeveloper\AmazingAddOn\Mcp;
51+
namespace ExpressionengineDeveloper\ControlPanel\Routes;
4752
4853
use ExpressionEngine\Service\Addon\Controllers\Mcp\AbstractRoute;
4954
@@ -68,7 +73,7 @@ class Index extends AbstractRoute
6873
'color' => 'Green'
6974
];
7075
71-
$this->setBody('McpIndex', $variables);
76+
$this->setBody('Index', $variables);
7277
7378
return $this;
7479
}
@@ -81,7 +86,7 @@ Let's dissect the starter file:
8186
`$cp_page_title` defines what is rendered in the `<title>` tag in the browser.
8287

8388
### `function process($id = false)`
84-
The `process()` function, similar to other functionality in your add-on, is the meat of your `Mcp` file. This is where you will render views, add sidebars, and add any necessary logic.
89+
The `process()` function, similar to other functionality in your add-on, is the meat of your route file. This is where you will render views, add sidebars, and add any necessary logic.
8590

8691
## Adding Content To Your Page
8792

@@ -99,9 +104,9 @@ Located at the top of the Control Panel screen, breadcrumbs help users easily kn
99104

100105
![Add-on Breadcrumbs](_images/addon_breadcrumbs.png)
101106

102-
To add a breadcrumb for your current MCP page, simply use `$this->addBreadcrumb()`.
107+
To add a breadcrumb for your current Control Panel page, simply use `$this->addBreadcrumb()`.
103108

104-
In the starter MCP file created for you by the CLI you will already see `$this->addBreadcrumb('index', 'Home');`. This will add a breadcrumb similar to the one in the screen shot above (`Add-Ons -> [Add-On Name] -> Home`).
109+
In the starter route file created for you by the CLI you will already see `$this->addBreadcrumb('index', 'Home');`. This will add a breadcrumb similar to the one in the screen shot above (`Add-Ons -> [Add-On Name] -> Home`).
105110

106111
If you needed to add more levels to your breadcrumbs you can chain them together as such:
107112

@@ -126,11 +131,11 @@ Building sidebar.
126131
Sidebar created successfully!
127132
```
128133

129-
This will create the file `Mcp/Sidebar.php` in your add-on's folder.
134+
This will create the file `ControlPanel/Sidebar.php` in your add-on's folder.
130135

131136
```
132137
amazing_add_on
133-
Mcp/
138+
ControlPanel
134139
┃ ┣ Sidebar.php
135140
┗ ...
136141
```
@@ -142,7 +147,7 @@ Inside of our `Sidebpar.php` file we'll have the following:
142147
```
143148
<?php
144149
145-
namespace ExpressionEngineDeveloper\AmazingAddOn\Mcp;
150+
namespace ExpressionEngineDeveloper\ControlPanel\Routes;
146151
147152
use ExpressionEngine\Service\Addon\Controllers\Mcp\AbstractSidebar;
148153
@@ -161,19 +166,20 @@ class Sidebar extends AbstractSidebar
161166
```
162167

163168
#### Automatically Generate Your Sidebar
164-
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.
169+
If you'd like to have your sidebar automatically generated then that's it! The `Sidebar` class will scan our `ControlPanel/Routes` 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.
165170

166171
Example:
167172

168173
With an add-on folder like this:
169174

170175
```
171176
amazing_add_on
172-
┣ Mcp
173-
┃ ┣ Configurations.php
174-
┃ ┣ Settings.php
175-
┃ ┣ Licenses.php
176-
┃ ┣ Index.php
177+
┣ ControlPanel
178+
┃ ┣ Routes
179+
┃ ┃ ┣ Configurations.php
180+
┃ ┃ ┣ Settings.php
181+
┃ ┃ ┣ Licenses.php
182+
┃ ┃ ┣ Index.php
177183
┃ ┗ Sidebar.php
178184
┗ ...
179185
```
@@ -183,7 +189,7 @@ Would produce a sidebar in the Control Panel like this:
183189
![control panel sidebar](_images/addon_sidebar_start.png)
184190

185191

186-
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:
192+
You can take this a step further by adjusting the following properties in your Control Panel routes (`ControlPanel/Routes/[route_name].php`) to adjust how sidebar items are displayed:
187193
##### `protected $sidebar_title (string)`
188194
By default the sidebar link text is based on your route's name. This property will overwrite the text displayed for this route.
189195

@@ -203,11 +209,11 @@ Inserts a divider in the sidebar before the link to this route.
203209
Inserts a divider in the sidebar after the link to this route.
204210

205211

206-
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).
212+
You can even modify the generated sidebar in the `process()` method of your `ControlPanel/Routes/Sidebar.php` file by utilizing the [`CP/Sidebar Service`](development/services/sidebar.md).
207213

208214
#### Manually Generate Your Sidebar
209215

210-
We will set the `$automatic` property in our `Mcp/Sidebar.php` file to `false`.
216+
We will set the `$automatic` property in our `ControlPanel/Routes/Sidebar.php` file to `false`.
211217

212218
```
213219
public $automatic = false;
@@ -256,7 +262,7 @@ There are two ways to output to the main body of your add-on's page.
256262
- HTML String
257263
- Using Views
258264

259-
The `setBody()` method is smart enough to know what you're trying to do. If you pass a single parameter to the method such as `$this->setBody($myString)`, the method knows you are only passing a single string to be rendered on your page. However, if you pass multiple parameters such as `$this->setBody('McpIndex', $variables);`, the method knows that you are passing a View and an array of variables that should be passed to the View.
265+
The `setBody()` method is smart enough to know what you're trying to do. If you pass a single parameter to the method such as `$this->setBody($myString)`, the method knows you are only passing a single string to be rendered on your page. However, if you pass multiple parameters such as `$this->setBody('Index', $variables);`, the method knows that you are passing a View and an array of variables that should be passed to the View.
260266

261267
Continue reading to see examples of how to use these two options.
262268

@@ -285,22 +291,22 @@ If you would like to make this page more dynamic or include additional functiona
285291

286292
#### Views
287293

288-
When your add-on was created via the CLI a `views` folder was also created in your add-on's folder. Inside of this folder a file was also created, `views/McpIndex.php`. By default this Control Panel page is already using the [View service](/development/services/view.md) by calling `$this->setBody()`.
294+
When your add-on was created via the CLI a `views` folder was also created in your add-on's folder. Inside of this folder a file was also created, `views/Index.php`. By default this Control Panel page is already using the [View service](/development/services/view.md) by calling `$this->setBody()`.
289295

290296
```
291297
$variables = [
292298
'name' => 'Matt',
293299
'color' => 'Green'
294300
];
295301
296-
$this->setBody('McpIndex', $variables);
302+
$this->setBody('Index', $variables);
297303
```
298304

299-
As we can see here, the `Mcp` file is passing two arguments to `$this->setBody()`:
300-
- `McpIndex` is the name of the corresponding view to use (references `views/McpIndex.php`)
305+
As we can see here, the route file is passing two arguments to `$this->setBody()`:
306+
- `Index` is the name of the corresponding view to use (references `views/Index.php`)
301307
- `$variables` is an array of variables that will be available to the view.
302308

303-
Now let's look at the view itself, found at `views/McpIndex.php`.
309+
Now let's look at the view itself, found at `views/Index.php`.
304310

305311
```
306312
<?php
@@ -346,7 +352,7 @@ private function getForm()
346352
}
347353
```
348354

349-
Now, let's add that to our `Mcp` file and be sure to pass the array returned from `getForm()` to our view.
355+
Now, let's add that to our route file and be sure to pass the array returned from `getForm()` to our view.
350356

351357
```
352358
public function process($id = false)
@@ -365,7 +371,7 @@ public function process($id = false)
365371
'form' => $form
366372
];
367373
368-
$this->setBody('McpIndex', $variables);
374+
$this->setBody('Index', $variables);
369375
370376
return $this;
371377
}
@@ -385,7 +391,7 @@ private function getForm()
385391
}
386392
```
387393

388-
Since we passed our form to our view in the `$variables` array, inside of `views/McpIndex.php` we can now use the View service to render our `$form` array as the main body of our Control Panel page.
394+
Since we passed our form to our view in the `$variables` array, inside of `views/Index.php` we can now use the View service to render our `$form` array as the main body of our Control Panel page.
389395

390396
```
391397
if (isset($form)) {
@@ -410,26 +416,26 @@ Often your add-on will need more than one page in the Control Panel. The CLI mak
410416
Start with:
411417

412418
```
413-
php system/ee/eecli.php make:mcp-route
419+
php system/ee/eecli.php make:cp-route
414420
```
415421

416-
This adds a new file to your `Mcp` folder which will act similar to the Index page we discussed above, along with a matching View in our `views` folder.
422+
This adds a new file to your `ControlPanel/Routes` folder which will act similar to the Index page we discussed above, along with a matching View in our `views` folder.
417423

418-
Now inside of your `/Mcp` folder you have a new file and matching Mcp class based on the name you chose in the CLI. This page will be accessible based on the class name you provided. For example:
424+
Now inside of your `ControlPanel/Routes` folder you have a new file and matching class based on the name you chose in the CLI. This page will be accessible based on the class name you provided. For example:
419425

420426
```
421-
php system/ee/eecli.php make:mcp-route
427+
php system/ee/eecli.php make:cp-route
422428
View name? configurations
423429
Which add-on would you like to add this to? amazing_add_on
424430
Mcp successfully created!
425431
```
426432

427-
This will create a file in my `Mcp` folder called `Configurations.php` which will look like this:
433+
This will create a file in my `ControlPanel/Routes` folder called `Configurations.php` which will look like this:
428434

429435
```
430436
<?php
431437
432-
namespace ExpressionengineDeveloper\AmazingAddOn\Mcp;
438+
namespace ExpressionengineDeveloper\ControlPanel\Routes;
433439
434440
use ExpressionEngine\Service\Addon\Controllers\Mcp\AbstractRoute;
435441
@@ -453,7 +459,7 @@ class Configurations extends AbstractRoute
453459
'color' => 'Green'
454460
];
455461
456-
$this->setBody('McpIndex', $variables);
462+
$this->setBody('Index', $variables);
457463
458464
return $this;
459465
}

0 commit comments

Comments
 (0)