Important
You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.
See our Release Process documentation for more information on the currently supported and upcoming releases.
Set Up Mass Action in Datagrid¶
How to setup datagrid mass actions in Management Console described in Mass Action Datagrid Extension article.
Let’s consider using mass delete of customer users in the storefront datagrid page. First, check that oro_datagrid_front_mass_action route is enabled for the frontend. In routing.yml, add the frontend: true option:
1 oro_datagrid_front_mass_action:
2 ...
3 options:
4 frontend: true
In the corresponding grid configuration (datagrids.yml), specify the following options:
1 frontend-customer-customer-user-grid:
2 ...
3 mass_actions:
4 delete:
5 label: Delete
6 type: delete
7 icon: trash
8 entity_name: Oro\Bundle\CustomerBundle\Entity\CustomerUser
9 data_identifier: customerUser.id
10 name: delete
11 frontend_type: delete-mass
12 route: oro_datagrid_front_mass_action
13 acl_resource: oro_customer_frontend_customer_user_delete
14 handler: oro_customer.datagrid.extension.mass_action.handler.delete
Next, add mass_actions section with params below:
delete specifies the type of mass action
entity_name, data_identifier describes the main entity and its identifier
frontend_type: delete-mass points to use a predefined action located in DataGridBundle/Extension/MassAction/Actions/Ajax/DeleteMassAction.php
route - a route used for mass action processing. In our case: oro_datagrid_front_mass_action
acl_resource - an ACL resource identifier
handler - a service, responsible for mass delete handling. For example, a logged user should not be allowed to delete themselves. For this case we extend DeleteMassActionHandler with our custom logic:
1 use Oro\Bundle\CustomerBundle\Entity\CustomerUser;
2 use Oro\Bundle\DataGridBundle\Extension\MassAction\DeleteMassActionHandler;
3
4 class CustomersDeleteActionHandler extends DeleteMassActionHandler
5 {
6 /**
7 * {@inheritdoc}
8 */
9 protected function isDeleteAllowed($entity)
10 {
11 /** @var CustomerUser $entity */
12 if ($this->tokenAccessor->getUserId() === $entity->getId()) {
13 return false;
14 }
15
16 return parent::isDeleteAllowed($entity);
17 }
18 }
and register the service:
1 oro_customer.datagrid.extension.mass_action.handler.delete:
2 class: Oro\Bundle\CustomerBundle\Datagrid\Extension\MassAction\CustomersDeleteActionHandler
3 parent: oro_datagrid.extension.mass_action.handler.delete