From d525f336c2e0a48fbdf62b0a9e5e7aa0927ad872 Mon Sep 17 00:00:00 2001 From: Adrian Dumitrache Date: Mon, 20 May 2024 18:24:10 +0300 Subject: [PATCH] [SonataExtraBundle] Improve AutoActionExtension to detect if actions exist (#267) --- .../Extension/AutoActionExtension.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/sonata-extra-bundle/Extension/AutoActionExtension.php b/packages/sonata-extra-bundle/Extension/AutoActionExtension.php index a61af9b8b..84001efa8 100644 --- a/packages/sonata-extra-bundle/Extension/AutoActionExtension.php +++ b/packages/sonata-extra-bundle/Extension/AutoActionExtension.php @@ -38,13 +38,24 @@ public function configureListFields(ListMapper $list): void } } - $list->add( - ListMapper::NAME_ACTIONS, - ListMapper::TYPE_ACTIONS, - [ - 'label' => 'Action', - 'actions' => $this->actions, - ] - ); + $actions = []; + $routes = $admin->getRoutes(); + + foreach ($this->actions as $action => $options) { + if ($routes->has($routes->getCode($action))) { + $actions[$action] = $options; + } + } + + if (!empty($actions)) { + $list->add( + ListMapper::NAME_ACTIONS, + ListMapper::TYPE_ACTIONS, + [ + 'label' => 'Action', + 'actions' => $actions, + ] + ); + } } }