Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f22dc6

Browse files
committedMar 20, 2025··
feat(docs): restructure API documentation and add installation guide
Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
1 parent e7cb2da commit 6f22dc6

File tree

2 files changed

+257
-254
lines changed

2 files changed

+257
-254
lines changed
 

‎README.md

+3-254
Original file line numberDiff line numberDiff line change
@@ -18,260 +18,9 @@ The TastyIgniter Automation extension allows you to automate certain actions wit
1818
- Global parameters available to all automation rules
1919
- Extendable with custom events, actions, and conditions
2020

21-
## Installation
21+
## Documentation
2222

23-
You can install the extension via composer using the following command:
24-
25-
```bash
26-
composer require tastyigniter/ti-ext-automation:"^4.0" -W
27-
```
28-
29-
Run the database migrations to create the required tables:
30-
31-
```bash
32-
php artisan igniter:up
33-
```
34-
35-
## Automation workflow
36-
37-
The Automation extension follows a specific workflow when an automation is triggered:
38-
39-
1. The extension registers associated actions, conditions, and events using the registerAutomationRules method.
40-
2. When a system event is triggered, the parameters of the event are captured, along with any global parameters.
41-
3. These captured parameters are then attached to a job and placed onto the queue for background processing.
42-
4. The job retrieves all automation rules that match the triggered system event and runs them.
43-
5. The automation conditions are checked to ensure that any required conditions are met.
44-
6. Finally, the automation actions associated with the triggered rules are executed using the captured parameters.
45-
46-
## Usage
47-
48-
You can manage automations in the admin panel by navigating to Tools > Automations.
49-
50-
### Defining events
51-
52-
An event class is responsible for preparing the parameters passed to the conditions and actions.
53-
54-
Automation Event classes are typically stored in the `src/AutomationRules/Events` directory of an extension. The Event class is a simple class that extends `Igniter\Automation\Classes\BaseEvent` and defines the `eventDetails` and `makeParamsFromEvent` methods.
55-
56-
Here is an example of an event class:
57-
58-
```php
59-
namespace Author\Extension\AutomationRules\Events;
60-
61-
class CustomerRegisteredEvent extends \Igniter\Automation\Classes\BaseEvent
62-
{
63-
public function eventDetails(): array
64-
{
65-
return [
66-
'name' => 'Registered',
67-
'description' => 'When a customer registers',
68-
'group' => 'customer'
69-
];
70-
}
71-
72-
public static function makeParamsFromEvent(array $args, $eventName = null): array
73-
{
74-
return [
75-
'user' => array_get($args, 0)
76-
];
77-
}
78-
}
79-
```
80-
81-
The `eventDetails` method returns information about the event, including the name and description. The `makeParamsFromEvent` method prepares the captured parameters passed to the conditions and actions.
82-
83-
These are the available options for the `eventDetails` method:
84-
85-
- `name` - The name of the event. This is displayed in the admin panel.
86-
- `description` - A description of the event. This is displayed in the admin panel.
87-
- `group` - The group to which the event belongs. This is used to group events in the admin panel.
88-
89-
### Defining actions
90-
91-
A action class defines the final step in an automation and performs the automation.
92-
93-
Action classes are typically stored in the `src/AutomationRules/Actions` directory of an extension. The Action class is a simple class that extends `Igniter\Automation\Classes\BaseAction` and defines the `actionDetails`, `defineFormFields`, and `triggerAction` methods.
94-
95-
```php
96-
namespace Author\Extension\AutomationRules\Actions;
97-
98-
class SendMailTemplate extends \Igniter\Automation\Classes\BaseAction
99-
{
100-
public function actionDetails(): array
101-
{
102-
return [
103-
'name' => 'Compose a mail message',
104-
'description' => 'Send a message to a recipient',
105-
];
106-
}
107-
108-
public function defineFormFields(): array
109-
{
110-
return [
111-
'fields' => [
112-
'template' => [
113-
'label' => 'lang:igniter.user::default.label_template',
114-
'type' => 'select',
115-
],
116-
'send_to' => [
117-
'label' => 'lang:igniter.user::default.label_send_to',
118-
'type' => 'select',
119-
],
120-
],
121-
];
122-
}
123-
124-
public function triggerAction($params)
125-
{
126-
$email = $this->model->send_to;
127-
$template = $this->model->template;
128-
129-
// Send mail
130-
}
131-
}
132-
```
133-
134-
The `actionDetails` method returns information about the action, including the name and description. The `defineFormFields` method defines the form fields required for the action, see [TastyIgniter's available form field types](https://tastyigniter.com/docs/advanced/forms#available-field-types). You can access fields defined in the `defineFormFields` method using `$this->model->field_name`. The `triggerAction` method performs the automation action.
135-
136-
These are the available options for the `actionDetails` method:
137-
138-
- `name` - The name of the action. This is displayed in the admin panel.
139-
- `description` - A description of the action. This is displayed in the admin panel.
140-
141-
### Defining conditions
142-
143-
A condition class is used to check whether a condition is true or false.
144-
145-
Automation condition classes are typically stored in the extensions's `src/AutomationRules/Conditions` directory. The Condition class is a simple class that extends `Igniter\Automation\Classes\BaseCondition` and defines the `conditionDetails` and `isTrue` methods.
146-
147-
```php
148-
namespace Author\Extension\AutomationRules\Conditions;
149-
150-
class MyCondition extends \Igniter\Automation\Classes\BaseCondition
151-
{
152-
public function conditionDetails(): array
153-
{
154-
return [
155-
'name' => 'Condition',
156-
'description' => 'My Condition is checked',
157-
];
158-
}
159-
160-
public function isTrue(&$params): bool
161-
{
162-
return true;
163-
}
164-
}
165-
```
166-
167-
The `conditionDetails` method returns information about the condition, including the name and description. The `isTrue` method checks whether the condition is true for the specified parameters.
168-
169-
These are the available options for the `conditionDetails` method:
170-
171-
- `name` - The name of the condition. This is displayed in the admin panel.
172-
- `description` - A description of the condition. This is displayed in the admin panel.
173-
174-
### Defining model attribute conditions
175-
176-
Just like the condition class above, a model attribute condition class applies conditions to sets of model attributes.
177-
178-
Automation model attribute condition classes are typically stored in the extensions's `src/AutomationRules/Conditions` directory. The model attribute condition class is a simple class that extends `Igniter\Automation\Classes\BaseCondition` and defines the `conditionDetails`, `defineModelAttributes`, and `isTrue` methods.
179-
180-
```php
181-
namespace Author\Extension\AutomationRules\Conditions;
182-
183-
class CustomerAttribute extends \Igniter\Automation\Classes\BaseCondition
184-
{
185-
public function conditionDetails(): array
186-
{
187-
return [
188-
'name' => 'Customer attribute',
189-
];
190-
}
191-
192-
public function defineModelAttributes(): array
193-
{
194-
return [
195-
'first_name' => [
196-
'label' => 'First Name',
197-
],
198-
'last_name' => [
199-
'label' => 'Last Name',
200-
],
201-
];
202-
}
203-
204-
public function isTrue(&$params): bool
205-
{
206-
return true;
207-
}
208-
}
209-
```
210-
211-
The `defineModelAttributes` method defines the model attributes and labels required for the condition.
212-
213-
### Registering automation events, actions, and conditions
214-
215-
After creating the [event](#defining-events), [action](#defining-actions) and [condition](#defining-conditions) classes, you can make them available in the admin panel by registering them in the `registerAutomationRules` method of the extension class.
216-
217-
The `registerAutomationRules` method should return an array with the following keys:
218-
219-
- `events` - an array of event class that triggers an automation.
220-
- `actions` - an array of action class that performs a task when an automation is triggered.
221-
- `conditions` - an array of condition class that checks whether a condition is true or false before an action is performed.
222-
- `presets` - predefined automation rules available in the admin panel.
223-
224-
```php
225-
public function registerAutomationRules(): array
226-
{
227-
return [
228-
'events' => [
229-
\Igniter\User\AutomationRules\Events\CustomerRegistered::class,
230-
],
231-
'actions' => [
232-
\Igniter\User\AutomationRules\Actions\SendMailTemplate::class,
233-
],
234-
'conditions' => [
235-
\Igniter\User\AutomationRules\Conditions\CustomerAttribute::class
236-
],
237-
'presets' => [
238-
'registration_email' => [
239-
'name' => 'Send customer registration email',
240-
'event' => \Igniter\User\AutomationRules\Events\CustomerRegistered::class,
241-
'actions' => [
242-
\Igniter\User\AutomationRules\Actions\SendMailTemplate::class => [
243-
'template' => 'igniter.user::mail.registration_email'
244-
],
245-
]
246-
]
247-
],
248-
];
249-
}
250-
```
251-
252-
### Registering global parameters
253-
254-
Global parameters are available to all automation rules. You can register global parameters in the `boot` method of the extension class.
255-
256-
```php
257-
use Igniter\User\Facades\Auth;
258-
use Igniter\Automation\Classes\EventManager;
259-
260-
public function boot()
261-
{
262-
resolve(EventManager::class)->registerGlobalParams([
263-
'customer' => Auth::customer()
264-
]);
265-
}
266-
```
267-
268-
### Permissions
269-
270-
The Automation extension registers the following permissions:
271-
272-
- `Igniter.Automation.Manage`: Control who can manage automations in the admin area.
273-
274-
For more on restricting access to the admin area, see the [TastyIgniter Permissions](https://tastyigniter.com/docs/extend/permissions) documentation.
23+
Documentation can be found on the [TastyIgniter documentation website](https://tastyigniter.com/docs/extensions/automation).
27524

27625
## Changelog
27726

@@ -287,7 +36,7 @@ Contributions are welcome! Please read [TastyIgniter's contributing guide](https
28736

28837
## Security vulnerabilities
28938

290-
For reporting security vulnerabilities, please see our [our security policy](https://github.com/tastyigniter/ti-ext-automation/security/policy).
39+
For reporting security vulnerabilities, please see [our security policy](https://github.com/tastyigniter/ti-ext-automation/security/policy).
29140

29241
## License
29342

There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.