From 54d6112be84a682262824efa792397cfa0140b54 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 4 Dec 2024 19:00:16 +0100 Subject: [PATCH] Fix action callables --- src/Factory/ActionFactory.php | 2 +- tests/Controller/ActionsCrudControllerTest.php | 7 ++++--- .../src/Controller/ActionsCrudController.php | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Factory/ActionFactory.php b/src/Factory/ActionFactory.php index a81e39c0e4..ff613d04ae 100644 --- a/src/Factory/ActionFactory.php +++ b/src/Factory/ActionFactory.php @@ -165,7 +165,7 @@ private function processActionLabel(ActionDto $actionDto, ?EntityDto $entityDto, return; } - if (\is_callable($label)) { + if (\is_callable($label) && $label instanceof \Closure) { $label = \call_user_func_array($label, array_filter([$entityDto?->getInstance()])); if (!\is_string($label) && !$label instanceof TranslatableInterface) { diff --git a/tests/Controller/ActionsCrudControllerTest.php b/tests/Controller/ActionsCrudControllerTest.php index 149e68e0cf..8dbd95db04 100644 --- a/tests/Controller/ActionsCrudControllerTest.php +++ b/tests/Controller/ActionsCrudControllerTest.php @@ -47,8 +47,9 @@ public function testDynamicLabels() { $crawler = $this->client->request('GET', $this->generateIndexUrl()); - static::assertSame('Action 5: Category 0', $crawler->filter('a.dropdown-item:contains("Action 5")')->text()); - static::assertSame('Action 6: Category 0', $crawler->filter('a.dropdown-item:contains("Action 6")')->text()); - static::assertSame('Action 7: Category 0', $crawler->filter('a.dropdown-item:contains("Action 7")')->text()); + static::assertSame('Action 5: Category 0', $crawler->filter('a.dropdown-item[data-action-name="action5"]')->text()); + static::assertSame('Action 6: Category 0', $crawler->filter('a.dropdown-item[data-action-name="action6"]')->text()); + static::assertSame('Action 7: Category 0', $crawler->filter('a.dropdown-item[data-action-name="action7"]')->text()); + static::assertSame('Reset', $crawler->filter('a.dropdown-item[data-action-name="action8"]')->text()); } } diff --git a/tests/TestApplication/src/Controller/ActionsCrudController.php b/tests/TestApplication/src/Controller/ActionsCrudController.php index 425deb2a29..fdf0b68f27 100644 --- a/tests/TestApplication/src/Controller/ActionsCrudController.php +++ b/tests/TestApplication/src/Controller/ActionsCrudController.php @@ -40,6 +40,9 @@ public function configureActions(Actions $actions): Actions $action7 = Action::new('action7')->linkToCrudAction('')->setLabel(fn (Category $category) => t('Action %number%: %name%', ['%number%' => 7, '%name%' => $category->getName()])); + // this tests that the 'Reset' label is interpreted as a string and not as a callable to the PHP reset() function + $action8 = Action::new('action8')->linkToCrudAction('')->setLabel('Reset'); + return $actions ->add(Crud::PAGE_INDEX, $action1) ->add(Crud::PAGE_INDEX, $action2) @@ -48,6 +51,7 @@ public function configureActions(Actions $actions): Actions ->add(Crud::PAGE_INDEX, $action5) ->add(Crud::PAGE_INDEX, $action6) ->add(Crud::PAGE_INDEX, $action7) + ->add(Crud::PAGE_INDEX, $action8) ->update(Crud::PAGE_INDEX, Action::NEW, function (Action $action) { return $action->setIcon('fa fa-fw fa-plus')->setLabel(false); })