You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -83,33 +83,33 @@ Below is the complete structure of an add-on that we'll call "Amazing Add-on". T
83
83
```
84
84
amazing_add_on
85
85
┣ Commands
86
-
┃ ┣ CommandAnAmazingCommand.php
86
+
┃ ┗ CommandAnAmazingCommand.php
87
87
┣ database
88
88
┃ ┣ migrations
89
89
┃ ┃ ┗ 2022_11_14_170449_amazing_migration.php
90
90
┣ Extensions
91
91
┃ ┣ TemplatePostParse.php
92
92
┃ ┗ TypographyParseTypeEnd.php
93
-
┣ Mcp
93
+
┣ ControlPanel
94
+
┃ ┣ Routes
95
+
┃ ┃ ┣ Index.php
96
+
┃ ┃ ┗ Page2.php
94
97
┃ ┣ 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
102
102
┣ Model
103
-
┃ ┣ AmazingModel.php
103
+
┃ ┗ AmazingModel.php
104
104
┣ language
105
105
┃ ┣ english
106
106
┃ ┃ ┣ amazing_add_on_lang.php
107
107
┃ ┃ ┗ index.html
108
108
┃ ┗ index.html
109
109
┣ widgets
110
-
┃ ┣ AnAmazingWidget.php
110
+
┃ ┗ AnAmazingWidget.php
111
111
┣ views
112
-
┃ ┣ McpIndex.php
112
+
┃ ┣ Index.php
113
113
┃ ┗ Page2.php
114
114
┣ addon.setup.php
115
115
┣ ext.amazing_add_on.php
@@ -147,7 +147,7 @@ Reference [Adding Fieldtypes](development/fieldtypes/fieldtypes.md) for more inf
147
147
148
148
### The Mcp File (`mcp.[addon_name].php`)
149
149
**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).
151
151
Reference [Adding Control Panel Pages](development/modules.md) for more information on adding Control Panel pages with your add-on.
152
152
153
153
### 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
173
173
174
174
TIP: Reference the [Extensions](development/extensions.md) section of the docs for more information on using extensions in your add-on.
175
175
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.
178
178
Reference [Adding Actions](development/actions.md) for more information on creating URL endpoints (actions) with your add-on.
179
179
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.
182
182
Reference [Adding Control Panel Pages](development/modules.md) for more information on adding Control Panel routes and pages with your add-on.
183
183
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.
186
186
Reference [Adding Template Tags](development/custom-template-tags.md) for more information on adding template tags with your add-on.
Copy file name to clipboardExpand all lines: docs/development/modules.md
+45-39Lines changed: 45 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,34 +16,39 @@ lang: php
16
16
[TOC=2-3]
17
17
18
18
## 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.
20
20
21
21
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.
22
22
23
23
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.
24
24
25
25
## Creating An Amazing Control Panel Route
26
26
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.
28
28
29
29
```
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!
31
36
```
32
37
33
38
Follow the prompts to add the route to your add-on.
34
39
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.
36
41
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.
38
43
39
44
40
45
## 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:
use ExpressionEngine\Service\Addon\Controllers\Mcp\AbstractRoute;
49
54
@@ -68,7 +73,7 @@ class Index extends AbstractRoute
68
73
'color' => 'Green'
69
74
];
70
75
71
-
$this->setBody('McpIndex', $variables);
76
+
$this->setBody('Index', $variables);
72
77
73
78
return $this;
74
79
}
@@ -81,7 +86,7 @@ Let's dissect the starter file:
81
86
`$cp_page_title` defines what is rendered in the `<title>` tag in the browser.
82
87
83
88
### `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.
85
90
86
91
## Adding Content To Your Page
87
92
@@ -99,9 +104,9 @@ Located at the top of the Control Panel screen, breadcrumbs help users easily kn
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()`.
103
108
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`).
105
110
106
111
If you needed to add more levels to your breadcrumbs you can chain them together as such:
107
112
@@ -126,11 +131,11 @@ Building sidebar.
126
131
Sidebar created successfully!
127
132
```
128
133
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.
130
135
131
136
```
132
137
amazing_add_on
133
-
┣ Mcp/
138
+
┣ ControlPanel
134
139
┃ ┣ Sidebar.php
135
140
┗ ...
136
141
```
@@ -142,7 +147,7 @@ Inside of our `Sidebpar.php` file we'll have the following:
use ExpressionEngine\Service\Addon\Controllers\Mcp\AbstractSidebar;
148
153
@@ -161,19 +166,20 @@ class Sidebar extends AbstractSidebar
161
166
```
162
167
163
168
#### 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.
165
170
166
171
Example:
167
172
168
173
With an add-on folder like this:
169
174
170
175
```
171
176
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
177
183
┃ ┗ Sidebar.php
178
184
┗ ...
179
185
```
@@ -183,7 +189,7 @@ Would produce a sidebar in the Control Panel like this:
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:
187
193
##### `protected $sidebar_title (string)`
188
194
By default the sidebar link text is based on your route's name. This property will overwrite the text displayed for this route.
189
195
@@ -203,11 +209,11 @@ Inserts a divider in the sidebar before the link to this route.
203
209
Inserts a divider in the sidebar after the link to this route.
204
210
205
211
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).
207
213
208
214
#### Manually Generate Your Sidebar
209
215
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`.
211
217
212
218
```
213
219
public $automatic = false;
@@ -256,7 +262,7 @@ There are two ways to output to the main body of your add-on's page.
256
262
- HTML String
257
263
- Using Views
258
264
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.
260
266
261
267
Continue reading to see examples of how to use these two options.
262
268
@@ -285,22 +291,22 @@ If you would like to make this page more dynamic or include additional functiona
285
291
286
292
#### Views
287
293
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()`.
289
295
290
296
```
291
297
$variables = [
292
298
'name' => 'Matt',
293
299
'color' => 'Green'
294
300
];
295
301
296
-
$this->setBody('McpIndex', $variables);
302
+
$this->setBody('Index', $variables);
297
303
```
298
304
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`)
301
307
-`$variables` is an array of variables that will be available to the view.
302
308
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`.
304
310
305
311
```
306
312
<?php
@@ -346,7 +352,7 @@ private function getForm()
346
352
}
347
353
```
348
354
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.
350
356
351
357
```
352
358
public function process($id = false)
@@ -365,7 +371,7 @@ public function process($id = false)
365
371
'form' => $form
366
372
];
367
373
368
-
$this->setBody('McpIndex', $variables);
374
+
$this->setBody('Index', $variables);
369
375
370
376
return $this;
371
377
}
@@ -385,7 +391,7 @@ private function getForm()
385
391
}
386
392
```
387
393
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.
389
395
390
396
```
391
397
if (isset($form)) {
@@ -410,26 +416,26 @@ Often your add-on will need more than one page in the Control Panel. The CLI mak
410
416
Start with:
411
417
412
418
```
413
-
php system/ee/eecli.php make:mcp-route
419
+
php system/ee/eecli.php make:cp-route
414
420
```
415
421
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.
417
423
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:
419
425
420
426
```
421
-
php system/ee/eecli.php make:mcp-route
427
+
php system/ee/eecli.php make:cp-route
422
428
View name? configurations
423
429
Which add-on would you like to add this to? amazing_add_on
424
430
Mcp successfully created!
425
431
```
426
432
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:
0 commit comments