|
1 | 1 | # Creating a custom action |
2 | 2 |
|
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 | +
|
0 commit comments