From 7f647ddea62ead6e07af66019894c790862d069a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Poirier=20Th=C3=A9or=C3=AAt?= Date: Sat, 10 Aug 2024 09:19:24 -0400 Subject: [PATCH] [SonataExtraBundle] DefaultActionExtension registered manually --- config/services.yaml | 9 ++++++ .../Extension/DefaultActionExtension.php | 31 +++++++++++++++---- .../DrawSonataExtraBundle.en.yaml | 2 +- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index ae57697d..bf96b73b 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -18,6 +18,15 @@ services: Draw\Component\Tester\Command\GenerateTraitCommand: ~ Draw\Component\Tester\Command\GenerateAssertsDocumentationPageCommand: ~ + # Sonata Admin services >>> + Draw\Bundle\SonataExtraBundle\ActionableAdmin\Extension\DefaultActionExtension: + class: 'Draw\Bundle\SonataExtraBundle\ActionableAdmin\Extension\DefaultActionExtension' + arguments: + $actions: ['delete'] + tags: + - { name: sonata.admin.extension, global: true } + # Sonata Admin services <<< + App\: resource: '../app/src' exclude: diff --git a/packages/sonata-extra-bundle/ActionableAdmin/Extension/DefaultActionExtension.php b/packages/sonata-extra-bundle/ActionableAdmin/Extension/DefaultActionExtension.php index a790bccb..a1cf9610 100644 --- a/packages/sonata-extra-bundle/ActionableAdmin/Extension/DefaultActionExtension.php +++ b/packages/sonata-extra-bundle/ActionableAdmin/Extension/DefaultActionExtension.php @@ -4,18 +4,37 @@ use Draw\Bundle\SonataExtraBundle\ActionableAdmin\AdminAction\DeleteAdminAction; use Sonata\AdminBundle\Admin\AbstractAdminExtension; -use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; -#[AutoconfigureTag('sonata.admin.extension', attributes: ['global' => true])] class DefaultActionExtension extends AbstractAdminExtension implements ActionableAdminExtensionInterface { + private const SUPPORTED_ACTIONS = [ + 'delete' => DeleteAdminAction::class, + ]; + + private array $actions; + + public function __construct( + array $actions = [] + ) { + $this->actions = array_values( + array_intersect( + $actions, + array_keys(self::SUPPORTED_ACTIONS) + ) + ); + } + public function getActions(array $actions): array { - if (\array_key_exists('delete', $actions)) { - return $actions; - } + foreach ($this->actions as $action) { + if (\array_key_exists($action, $actions)) { + continue; + } + + $actionClass = self::SUPPORTED_ACTIONS[$action]; - $actions['delete'] = new DeleteAdminAction(); + $actions[$action] = new $actionClass(); + } return $actions; } diff --git a/packages/sonata-extra-bundle/Resources/translations/DrawSonataExtraBundle.en.yaml b/packages/sonata-extra-bundle/Resources/translations/DrawSonataExtraBundle.en.yaml index db66256f..588277fb 100644 --- a/packages/sonata-extra-bundle/Resources/translations/DrawSonataExtraBundle.en.yaml +++ b/packages/sonata-extra-bundle/Resources/translations/DrawSonataExtraBundle.en.yaml @@ -9,4 +9,4 @@ execution.notification.skipped.reason: error: 'error' execution.action.delete: - label: 'Delete' \ No newline at end of file + label: 'Delete'