forked from sonata-project/SonataAdminBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preBatchAction to Admin Extension and add a pre_batch_action event
This adds a preBatchAction() method to the AbstractAdminExtension and AdminExtensionInterface (BC). This enables the AdminEventExtension to dispatch a BatchActionEvent of type pre_batch_action. Both the extension and the event provide points to hook into within your own code, just like this is possible for pre/post persist/update/delete. Fixes sonata-project#7516 "Implement an event for batch actions" Relates to sonata-project#6550 "Delete Event isn't triggered in Batch delete"
- Loading branch information
Showing
6 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,10 @@ | |
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
* | ||
* NEXT_MAJOR: Uncomment the actual definition of below methods inside the interface and remove these annotations. | ||
* | ||
* @method void preBatchAction(AdminInterface $admin, string $actionName, ProxyQueryInterface $query, array &$idx, bool $allElements = false) | ||
* | ||
* @phpstan-template T of object | ||
*/ | ||
interface AdminExtensionInterface | ||
|
@@ -127,6 +131,13 @@ public function getAccessMapping(AdminInterface $admin): array; | |
*/ | ||
public function configureBatchActions(AdminInterface $admin, array $actions): array; | ||
|
||
// NEXT_MAJOR: Uncomment the method definition | ||
///** | ||
// * @param mixed[] $idx | ||
// * @phpstan-param AdminInterface<T> $admin | ||
// */ | ||
//public function preBatchAction(AdminInterface $admin, string $actionName, ProxyQueryInterface $query, array &$idx, bool $allElements = false): void; | ||
|
||
/** | ||
* Get a chance to modify export fields. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Event; | ||
|
||
use Sonata\AdminBundle\Admin\AdminInterface; | ||
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
/** | ||
* This event is sent by hook: | ||
* - preBatchAction. | ||
* | ||
* You can register the listener to the event dispatcher by using: | ||
* - sonata.admin.event.batch_action.pre_batch_action) | ||
* - sonata.admin.event.batch_action.[admin_code].pre_batch_action (not implemented yet) | ||
* | ||
* @author Jochem Klaver <[email protected]> | ||
* | ||
* @phpstan-template T of object | ||
*/ | ||
final class BatchActionEvent extends Event | ||
{ | ||
public const TYPE_PRE_BATCH_ACTION = 'pre_batch_action'; | ||
public const TYPE_POST_BATCH_ACTION = 'post_batch_action'; // not implemented yet | ||
|
||
/** | ||
* @var AdminInterface<object> | ||
* @phpstan-var AdminInterface<T> | ||
*/ | ||
private $admin; | ||
|
||
/** | ||
* @var string | ||
* @phpstan-var self::TYPE_* | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $actionName; | ||
|
||
/** | ||
* @var ProxyQueryInterface | ||
*/ | ||
private $proxyQuery; | ||
|
||
/** | ||
* @var mixed[] | ||
*/ | ||
private $idx; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $allElements; | ||
|
||
/** | ||
* @param mixed[] $idx | ||
* @phpstan-param AdminInterface<T> $admin | ||
* @phpstan-param self::TYPE_* $type | ||
*/ | ||
public function __construct(AdminInterface $admin, string $type, string $actionName, ProxyQueryInterface $proxyQuery, array &$idx, bool $allElements = false) | ||
{ | ||
$this->admin = $admin; | ||
$this->type = $type; | ||
$this->actionName = $actionName; | ||
$this->proxyQuery = $proxyQuery; | ||
$this->idx = &$idx; | ||
$this->allElements = $allElements; | ||
} | ||
|
||
/** | ||
* @phpstan-return AdminInterface<T> | ||
*/ | ||
public function getAdmin(): AdminInterface | ||
{ | ||
return $this->admin; | ||
} | ||
|
||
/** | ||
* @phpstan-return self::TYPE_* | ||
*/ | ||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getActionName(): string | ||
{ | ||
return $this->actionName; | ||
} | ||
|
||
public function getProxyQuery(): ProxyQueryInterface | ||
{ | ||
return $this->proxyQuery; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function &getIdx(): array | ||
{ | ||
return $this->idx; | ||
} | ||
|
||
public function isAllElements(): bool | ||
{ | ||
return $this->allElements; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters