Skip to content

Commit f86b1e6

Browse files
author
Andy McCormick
committed
completed overview
1 parent 5f52594 commit f86b1e6

File tree

4 files changed

+60
-61
lines changed

4 files changed

+60
-61
lines changed

docs/cli/creating-a-command.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Follow the prompts to add a CLI command to your add-on.
1919
This will create a `Commands` folder in your add-on along with a class and file based on your command name.
2020

2121
```
22-
amazing_addon
22+
amazing_add_on
2323
┣ Commands
2424
┃ ┣ Command[CommandName].php
2525
```
@@ -29,7 +29,7 @@ amazing_addon
2929
We see that the CLI has added our `Commands` folder and created our new class. However, the CLI has also modified our `addon.setup.php` file as well.
3030

3131
```
32-
amazing_addon
32+
amazing_add_on
3333
┣ Commands
3434
┃ ┣ CommandAnAmazingCommand.php
3535
```
@@ -48,7 +48,7 @@ return [
4848
'namespace' => 'ExpressionengineDeveloper\AmazingAddon',
4949
'settings_exist' => true,
5050
'commands' => [
51-
'amazing_addon:make:amazing-things' => ExpressionengineDeveloper\AmazingAddon\Commands\CommandAnAmazingCommand::class,
51+
'amazing_add_on:make:amazing-things' => ExpressionengineDeveloper\AmazingAddon\Commands\CommandAnAmazingCommand::class,
5252
],
5353
5454
],
@@ -83,7 +83,7 @@ class CommandAnAmazingCommand extends Cli
8383
* signature of command
8484
* @var string
8585
*/
86-
public $signature = 'amazing_addon:make:amazing-things';
86+
public $signature = 'amazing_add_on:make:amazing-things';
8787
8888
/**
8989
* Public description of command
@@ -101,7 +101,7 @@ class CommandAnAmazingCommand extends Cli
101101
* How to use command
102102
* @var string
103103
*/
104-
public $usage = 'php eecli.php amazing_addon:make:amazing-things';
104+
public $usage = 'php eecli.php amazing_add_on:make:amazing-things';
105105
106106
/**
107107
* options available for use in command

docs/development/actions.md

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Follow the prompts to add an action file to your add-on.
2727
This will create an `Actions` folder inside our `Module` folder where will build out the code we want to run when a user hits our `ACT` URL. Inside our `Actions` folder the CLI will create a file with the same name as the method we defined when creating our action.
2828

2929
```
30-
amazing_addon
30+
amazing_add_on
3131
┣ Module
3232
┃ ┣ Actions
3333
┃ ┃ ┗ [MethodName].php
@@ -164,7 +164,11 @@ public function up()
164164
}
165165
...
166166
```
167-
- To set an action as CSRF exempt on creation, use the `--csrf_exempt` or `-c` flag in the CLI: `$ php system/ee/eecli.php make:action --csrf_exempt`
167+
- To set an action as CSRF exempt on creation, use the `--csrf_exempt` or `-c` flag in the CLI:
168+
169+
```
170+
$ php system/ee/eecli.php make:action --csrf_exempt
171+
```
168172

169173

170174

@@ -179,22 +183,14 @@ For this example we'll use a really basic form that would be found in our templa
179183

180184

181185
Create our action:
182-
183-
In our template:
184-
185186
```
186-
<form method="post" action="/?ACT=41">
187-
188-
<label for="fname">First name:</label><br>
189-
<input type="text" id="fname" name="fname" value="John"><br>
190-
<label for="lname">Last name:</label><br>
191-
<input type="text" id="lname" name="lname" value="Doe"><br><br>
192-
<input type="submit" value="Submit">
193-
194-
</form>
195-
187+
$ php system/ee/eecli.php make:action --install
188+
What is the action name? ExampleAction
189+
What add-on is the action being added to? [amazing_add_on,...]: amazing_add_on
196190
```
197191

192+
This creates our required files. Now we had some functionality to our action which will add the first and last name submitted from a form to our custom database table.
193+
198194
Our action code:
199195

200196
```
@@ -225,6 +221,22 @@ class ExampleAction extends AbstractRoute
225221
}
226222
```
227223

224+
In our template:
225+
226+
```
227+
<form method="post" action="/?ACT=41">
228+
229+
<label for="fname">First name:</label><br>
230+
<input type="text" id="fname" name="fname" value="John"><br>
231+
<label for="lname">Last name:</label><br>
232+
<input type="text" id="lname" name="lname" value="Doe"><br><br>
233+
<input type="submit" value="Submit">
234+
235+
</form>
236+
237+
```
238+
239+
228240
**A note about action IDs.** For the example above, we looked up the action ID in the database. However, the action ID of your method may be different in your database than someone else as the IDs are auto-incremented by the database on insertion. Therefore, it's always best practice to fetch your action ID for use in a template by using the [`fetch_action_id()`](/development/legacy/libraries/cp.md#fetch_action_idclass-method) method from the `CP Class` library.
229241

230242
We would do this in our add-on with something like this:
@@ -238,6 +250,13 @@ $aid = ee()->cp->fetch_action_id(`Amazing_add_on`, `ExampleAction`);
238250

239251
In this next example we are just creating an endpoint which will be reachable from servers outside of our domain. We are going to expect the application to use cURL or similar libray to post an ID to our endpoint. Upon receiving the request our action will return the name of the entry matching the ID if it exists.
240252

253+
Create our action:
254+
```
255+
$ php system/ee/eecli.php make:action --install
256+
What is the action name? ExampleAction
257+
What add-on is the action being added to? [amazing_add_on,...]: amazing_add_on
258+
```
259+
241260
Our action code:
242261

243262
```
@@ -279,9 +298,7 @@ However, when I attempt to reach this endpoint from another application I get an
279298

280299
The request:
281300
```
282-
curl --location --request POST 'https://anamzingwebsite.test/?ACT=41' \
283-
--form 'id="1
284-
"'
301+
curl --location --request POST 'https://anamzingwebsite.test/?ACT=41' --form 'id="1"'
285302
```
286303

287304
The response:
@@ -298,21 +315,8 @@ The response:
298315
</div>
299316
...
300317
```
301-
This is because of the [`csrf_exempt` value](#exp_actions) mentioned above. To fix this we can go into the `exp_actions` table of our database and update the `csrf_exempt` column to `1`. However, to adjust for future installations we need to adjust the `$actions` array of our `upd` file.
302-
303-
Here we are going to set the `csrf_exempt` value on installation of our add-on.
304-
```
305-
public $actions = [
306-
[
307-
'class' => 'Demo_addon',
308-
'method' => 'Example_Action',
309-
'csrf_exempt` => true
310-
]
311-
];
312-
```
318+
This is because of the [`csrf_exempt` value](#cross-site-request-forgerycsrf-exemption) mentioned above. To fix this we can go into the `exp_actions` table of our database and update the `csrf_exempt` column to `1`.
313319

314320
Now when I send that same request, I simply get the entry title I requested.
315321

316-
WARN: **Warning:** Use caution when making an action csrf exempt. First ensure you really need to do so, then also provide some sort of key or validation to ensure the incoming request is not malicious.
317-
318322

docs/development/custom-template-tags.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Now, let's update the class to read the timezone that is passed in:
3535
This will create an `Models/Tags` folder in your add-on.
3636

3737
```
38-
amazing_addon
38+
amazing_add_on
3939
┣ Module
4040
┃ ┗ Tags
4141
┃ ┃ ┗ ExampleTag.php
@@ -66,26 +66,21 @@ As we can see, the CLI has correctly created a new class using our tag's name in
6666

6767
Inside of our class is the `process()` method. Anything we want to happen when our template tag is used should be placed inside this `process()` function.
6868

69-
After your tag is created, you can use your tag by just using `{exp:[tag_name]}`. In the example above, we created a tag named "Example Tag". We can now use the tag `{exp:amazing_add_on:example_tag}` and the text "My Tag" will be outputted to my template.
69+
After your tag is created, you can use your tag by just using `{exp:[addon_name][tag_name]}`. In the example above, we created a tag named "Example Tag". We can now use the tag `{exp:amazing_add_on:example_tag}` and the text "My Tag" will be outputted to my template.
7070

7171

7272
## Tag Construction
7373

74-
A typical ExpressionEngine tag looks like this:
74+
A typical custom add-on tag looks like this:
7575

76-
{exp:channel:entries}
76+
{exp:amazing_add_on:bold}
7777

7878
The first segment is the tag identifier: {exp:. It tells the template engine that it has just encountered a tag.
7979

80-
The second segment is the "family" name: `{exp:channel`. There are different families of tags: channel, comments, members, email, stats, etc. In programming terms, the second segment is the name of the 'class' that is instantiated by the tag.
81-
82-
The above example would tell the template engine to dynamically instantiate the "channel" class.
83-
84-
The third segment indicates the 'function' from within a particular family of tags: `{exp:channel:entries}`. This example would tell ExpressionEngine you want to use the "entries" method in the "channel" class.
80+
The second segment is the add-on's name all lowercase and with no spaces or special characters. In this case, we're telling ExpressionEngine to look inside of the Amazing Add-On add-on.
8581

86-
A tag, therefore, mirrors an object oriented approach: `Class->method`:
82+
The third segment indicates the tag from inside the add-on to use. In this case it is the `bold` tag.
8783

88-
{exp:class_name:method_name}
8984

9085
### Two Kinds of Tags
9186

@@ -105,9 +100,9 @@ Tag pairs allow you to process the information contained between the tags. In th
105100
Single Tags are the easiest template tags to create and process. Here we'll add a single tag to our add-on using the CLI. We'll name the tag Amazing Text.
106101

107102
```
108-
php system/ee/eecli.php make:tag
103+
php system/ee/eecli.php make:template-tag
109104
What is the tag name? Amazing Text
110-
What add-on is the tag being added to? amazing_add_on
105+
What add-on is the tag being added to? [amazing_add_on,...]: amazing_add_on
111106
Tag created successfully!
112107
```
113108

@@ -160,9 +155,9 @@ You will be able to use this plugin anywhere in a Template. You can even put thi
160155
To create this tag pair, we'll use the CLI similarly to how we created a single tag.
161156

162157
```
163-
php system/ee/eecli.php make:tag
158+
php system/ee/eecli.php make:template-tag
164159
What is the tag name? bold
165-
What add-on is the tag being added to? amazing_add_on
160+
What add-on is the tag being added to? [amazing_add_on,...]: amazing_add_on
166161
Tag created successfully!
167162
```
168163

@@ -238,9 +233,9 @@ We will allow the following parameter choices:
238233
- `type="italic"`
239234

240235
```
241-
php system/ee/eecli.php make:tag
236+
php system/ee/eecli.php make:template-tag
242237
What is the tag name? format
243-
What add-on is the tag being added to? amazing_add_on
238+
What add-on is the tag being added to? [amazing_add_on,...]: amazing_add_on
244239
Tag created successfully!
245240
```
246241

@@ -304,7 +299,7 @@ First, generate the tag (we're calling our tag "date and time" and adding it to
304299
```
305300
php system/ee/eecli.php make:template-tag
306301
What is the tag name? date and time
307-
What add-on is the tag being added to? amazing_add_on
302+
What add-on is the tag being added to? [amazing_add_on,...]: amazing_add_on
308303
Tag created successfully!
309304
```
310305

@@ -382,4 +377,4 @@ The current date is: November 15, 2022
382377
The current time is: 02:40 PM
383378
```
384379

385-
TIP: Of course, this is only the begining of what you can do with variables in your tag. We created single variables here, but you can create pair variables and much more. For more information about this, and manipulating the tagdata in your plugin, check out the [Template Class](development/legacy/libraries/template.md).
380+
TIP: Of course, this is only the beginning of what you can do with variables in your tag. We created single variables here, but you can create pair variables and much more. For more information about this, and manipulating the tagdata in your plugin, check out the [Template Class](development/legacy/libraries/template.md).

docs/development/extensions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ TIP: Files that interact with ExpressionEngine core hooks are referred to as "ex
3434
This will create an `ext[addon_name].php` file in our add-on along with an `Extensions` folder where will build out the code we want to run when we interact with a core hook. Inside our `Extensions` folder the CLI will create a file with the same name as the core hook we plan to use.
3535

3636
```
37-
amazing_addon
37+
amazing_add_on
3838
┣ Extensions
3939
┃ ┣ [HookName].php
4040
┃ ...
41-
┗ ext.amazing_addon.php
41+
┗ ext.amazing_add_on.php
4242
```
4343

4444
TIP: A single add-on can interact with as many hooks as you want.
@@ -55,12 +55,12 @@ Here we have added the ability to interact with the [`typography_parse_type_end(
5555
So our add-on structure now looks like this:
5656

5757
```
58-
amazing_addon
58+
amazing_add_on
5959
┣ Extensions
6060
┃ ┣ TypographyParseTypeEnd.php
6161
┣ addon.setup.php
62-
┣ ext.amazing_addon.php
63-
┗ upd.amazing_addon.php
62+
┣ ext.amazing_add_on.php
63+
┗ upd.amazing_add_on.php
6464
```
6565

6666

0 commit comments

Comments
 (0)