From 5142ac39abdc51175638e8dfdff965f8491b6219 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 12 Oct 2023 16:05:19 +0200 Subject: [PATCH] add documentation for global batch actions --- docs/crud/configuration.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/crud/configuration.md b/docs/crud/configuration.md index caadd07..4ca8589 100644 --- a/docs/crud/configuration.md +++ b/docs/crud/configuration.md @@ -307,3 +307,33 @@ $configuration->setBatchAction( } ); ``` + +## setGlobalBatchAction + +`setGlobalBatchAction(string $context, string $action, string $label, callable $callack)` + +Add a global batch action. The callback has 3 arguments: + +* An instance of `App\Core\Repository\RepositoryQuery` +* An instance of `App\Core\Manager\EntityManager` +* An array of selected entities or a `null` value + +Do not use the same action in global and classic batch action. + +The callback can return a response. If not, the user will be redirect automatically. See the example below: + +```php-inline +use App\Core\Entity\EntityInterface; +use App\Core\Manager\EntityManager; + +$configuration->setGlobalBatchAction( + 'index', + 'export_json', + 'Export to JSON', + function(RepositoryQuery $query, EntityManager $manager, ?array $selection): ?Response { + $items = $selection ?? $query->find(); + + return $this->json($items); + } +); +```