Skip to content

Commit 091e6e9

Browse files
Merge pull request #27 from LIN3S/docs/customizations
Docs/customizations
2 parents 315201e + f9ea613 commit 091e6e9

4 files changed

Lines changed: 156 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/custom_list_field.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
11
# Creating a custom list field
2+
3+
In case you want to write your own list field column rendered you need to implement
4+
`LIN3S\AdminBundle\ListFields\ListFieldType`. The `render()` method is expected to return an already escaped
5+
string, can be HTML but be careful as it will be printed in the list without been escaped.
6+
7+
ListFieldTypes are usually generic and need to be associated with an entity in the configuration.
8+
9+
1. Create a new class implementing `LIN3S\AdminBundle\ListFields\ListFieldType`
10+
1. Add the class to Dependency Container with `lin3s_admin.list_field_type` tag name and the desired alias.
11+
1. Reference the created service with the alias in the property `type` of list > field > field_name of your `admin.yml`
12+
13+
## Header function
14+
15+
You can handle the header representation of the column within this function, these are the parameters available:
16+
* options: Array with the name of the field.
17+
* configuration: The configuration.
18+
19+
## Render function
20+
21+
You can handle the header representation of the row within this function, these are the parameters available:
22+
* entity: The entity to represent in the row.
23+
* options: Array with the options declared in admin.yml
24+
* configuration: The configuration.
25+
26+
## Translation
27+
28+
Translating header or rendered row content is possible adding the argument `"@translator.default"` to receive an
29+
instance of translator ready to use.

docs/custom_list_filter.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
11
# Creating a custom list filter
2+
3+
A list filter is an implementation that defines how an a filter input has to be rendered. This works together with the
4+
`AdminRepository` that receives the submitted form that was built using list filter types.
5+
6+
Using filters, you can implement customized search based on any field of your entities, although those already
7+
provided `text` and `date` may be enough for most project, perhaps you will need to customize or create more complex
8+
filters for your project specific business logic.
9+
10+
1. Create a new class implementing `LIN3S\AdminBundle\Configuration\Type\ListFilterType`
11+
1. Add the class to Dependency Container with `lin3s_admin.list_filter_type` tag name and the desired alias.
12+
1. Reference the created service with the alias in the property `type` of list > filters > field_name of your `admin.yml`
13+
14+
## Render function
15+
16+
You can handle the header representation of the row within this function, these are the parameters available:
17+
* filter: A `ListFilter` entity of the filter.
18+
* currentValue: The value to be filtered.
19+
* options: An array of options.
20+
21+
Text filter example:
22+
23+
```php
24+
$attributes = $currentValue !== null ? ' value="' . $currentValue . '"' : '';
25+
26+
foreach ($options['attrs'] as $attrName => $attr) {
27+
$attributes .= ' ' . $attrName . '="' . $attr . '"';
28+
}
29+
30+
return sprintf('<input %s type="text" data-filter-field="%s">', $attributes, $filter->field());
31+
```
32+
33+

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)