Skip to content

Commit f9ea613

Browse files
author
Aitor Brazaola
committed
Updated index with links.
Custom action docs.
1 parent 7878100 commit f9ea613

2 files changed

Lines changed: 96 additions & 1 deletion

File tree

docs/custom_action.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,92 @@
11
# Creating a custom action
22

3-
> TODO
3+
An action is any change that can be performed over a single entity. A creation, an edition, a state change... all of
4+
them are considered actions. Due to project requirements a variety of actions may be applied therefore, sometimes is not
5+
enough to use common CRUD actions. Even though, we provide built in new, edit and delete actions available under
6+
`LIN3S\AdminBundle\Action\Type` namespace and work well with Symfony Forms.
7+
8+
To create an action:
9+
1. Extend `LIN3S\AdminBundle\Action\ActionType` interface. This `ActionType` will receive a set of parameters and is
10+
expected to return a `Symfony\Component\HttpFoundation\Response` Common responses are a rendered twig template or a
11+
`RedirectResponse`.
12+
1. Add the class to Dependency Container with `lin3s_admin.action` tag name and the desired alias.
13+
1. Define the action in `admin.yml` in the entity where is going to be used. Example:
14+
```yaml
15+
my_entity:
16+
class: AdminBundle\Entity\MyEntity
17+
name:
18+
singular: admin.my_entity.name.singular
19+
plural: admin.my_entity.name.plural
20+
actions:
21+
my_action:
22+
type: my_custom_action_alias
23+
options:
24+
name: MyAction
25+
catchable_exceptions: AdminBundle\Entity\MyEntity\Exception\MyCustomException: admin.exception.my_entity.error_message
26+
...
27+
```
28+
29+
## The parameters
30+
* entity: The entity affected by this action.
31+
* config: The entity configuration.
32+
* request: The HTTP request
33+
* options: An array with the declared options.
34+
35+
## Action scope
36+
Once defined an action for an entity can be attached to global scope of the list or locally to each row of content.
37+
38+
### Global
39+
Adding an action in global scope creates a top button in list view with the name defined and iterates over all the
40+
entity rows calling axecute method per each.
41+
42+
Example:
43+
```yaml
44+
taxon_header:
45+
class: AdminBundle\Entity\MyEntity
46+
name:
47+
...
48+
actions:
49+
my_action:
50+
type: my_action
51+
options:
52+
name: MyAction
53+
list:
54+
fields:
55+
...
56+
filters:
57+
...
58+
global_actions: ["new", "my_action"]
59+
```
60+
61+
### Row
62+
Adding an action as row level creates a button in the action list column per row to launch itself affecting only to the
63+
row entity where the link button has been triggered.
64+
65+
Example:
66+
```yaml
67+
taxon_header:
68+
class: AdminBundle\Entity\TaxonHeader\TaxonHeader
69+
name:
70+
...
71+
actions:
72+
my_action:
73+
type: aitor_action
74+
options:
75+
name: MiAccion
76+
list:
77+
fields:
78+
my_fancy_entity_field:
79+
name: admin.my_entity.list.fields.my_fancy_entity_field
80+
type: string
81+
options:
82+
field: my_fancy_entity_field
83+
actions:
84+
name: lin3s_admin.list.table.actions
85+
type: actions
86+
options:
87+
actions: ['edit', 'my_action']
88+
filters:
89+
...
90+
global_actions: ...
91+
```
92+

docs/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Common responses are a rendered twig template or a `RedirectResponse`.
1919

2020
ActionTypes are usually generic and need to be associated with an entity in the configuration.
2121

22+
[More details](custom_action.md)
23+
2224
###ListFieldType
2325

2426
A list field type is an implementation that defines how a list table column will be rendered. This bundle implements
@@ -31,11 +33,15 @@ string, can be HTML but be careful as it will be printed in the list without bee
3133

3234
ListFieldTypes are usually generic and need to be associated with an entity in the configuration.
3335

36+
[More details](custom_list_field.md)
37+
3438
###ListFilters
3539

3640
A list filter is an implementation that defines how an a filter input has to be rendered. This works together with the
3741
`AdminRepository` that receives the submitted form that was built using list filter types.
3842

43+
[More details](custom_list_filter.md)
44+
3945
### Configuration reference
4046

4147
[Configuration reference docs](configuration_reference.md)

0 commit comments

Comments
 (0)