2lenet/crudit-bundle
Symfony bundle to rapidly build configurable CRUD back offices with SB Admin layout. Provides list views with pagination, sorting, actions, exports and batch ops, plus datasources, filters, menus, workflows, maps, markdown and Twig helpers.
The batch actions allow to perform a given action on the pre-selected items of the list.
In your src/Crudit/Config/EntityCrudConfig.php, you have to overload the getListActions() method of the
AbstractCrudConfig. Inside your getListActions() method, you can add a new action and add ->setIsBatch() to it:
public function getListActions(): array
{
$actions = parent::getListActions();
$actions[] = ListAction::new(
'action.batch.exporter',
Path::new('exporter_intervention'),
Icon::new('file-export')
)->setIsBatch();
return $actions;
}
Then, in your src/Controller/Crudit/EntityContoller.php you can write the method that the batch action is going to execute:
/**
* [@Route](https://github.com/Route)("/exporter_intervention", name="exporter_intervention")
*/
public function exporterInterventions(Request $request, ResourceResolver $resolver, Exporter $exporter)
{
if ((bool)$request->query->get('all_page')) {
// get data from datasource
...
} else {
$ids = explode(",", $request->get("ids"));
...
}
...
}
This will result in:

That's it!
After ->setIsBatch() you need to add ->setForm() and pass as parameter your form like this :
public function getListActions(): array
{
$actions = parent::getListActions();
$actions[] = ListAction::new(
'action.batch.exporter',
Path::new('exporter_intervention'),
Icon::new('file-export')
)->setIsBatch()->setForm(YourFormType::class);
return $actions;
}
In your form you can add all the fields you need, but just 1 is required :
public function buildForm(FormBuilderInterface $builder, array $options): void
{
// All the fields you need
$builder->add('intervention');
// The required fields
$builder->add('ids', HiddenType::class, [
'label' => false
]);
$builder->add('all_page', HiddenType::class, [
'label' => false
]);
}
Now in your controller you can find all the selected ids and the different values of your form like this :
/**
* [@Route](https://github.com/Route)("/exporter_intervention", name="exporter_intervention")
*/
public function exporterInterventions(Request $request, ResourceResolver $resolver, Exporter $exporter)
{
/** [@var](https://github.com/var) array $params */
$params = $request->request->get('exporter_intervention');
$intervention = $params['intervention'];
if ((bool)$params['all_page']) {
// get data from datasource
...
} else {
$ids = explode(',', $params['ids']);
...
}
...
}
How can I help you explore Laravel packages today?