diff --git a/src/Config/Actions.php b/src/Config/Actions.php index 7348f32f9d..3cfadda986 100644 --- a/src/Config/Actions.php +++ b/src/Config/Actions.php @@ -81,7 +81,7 @@ public function remove(string $pageName, string $actionName): self public function reorder(string $pageName, array $orderedActionNames): self { $newActionOrder = []; - $currentActions = $this->dto->getActions(); + $currentActions = $this->dto->getActionList(); foreach ($orderedActionNames as $actionName) { if (!\array_key_exists($actionName, $currentActions[$pageName])) { throw new \InvalidArgumentException(sprintf('The "%s" action does not exist in the "%s" page, so you cannot set its order.', $actionName, $pageName)); diff --git a/src/Dto/ActionConfigDto.php b/src/Dto/ActionConfigDto.php index bed0b2b0ca..35add9fa53 100644 --- a/src/Dto/ActionConfigDto.php +++ b/src/Dto/ActionConfigDto.php @@ -39,6 +39,9 @@ public function __clone() } } + /** + * @deprecated since 4.25.0 and it will be removed in EasyAdmin 5.0.0. + */ public function setPageName(?string $pageName): void { $this->pageName = $pageName; @@ -109,16 +112,55 @@ public function disableActions(array $actionNames): void /** * @return ActionCollection|array> + * + * @deprecated since 4.25.0 and it will be removed in EasyAdmin 5.0.0. Use `getPageActions` or `getActionList` instead. */ public function getActions(): ActionCollection|array { + trigger_deprecation( + 'easycorp/easyadmin-bundle', + '4.25.0', + 'Calling "%s" is deprecated and will be removed in 5.0.0. Use `getPageActions` or `getActionList` instead.', + __METHOD__, + ); + return null === $this->pageName ? $this->actions : ActionCollection::new($this->actions[$this->pageName]); } + public function getPageActions(string $pageName): ActionCollection + { + return ActionCollection::new($this->actions[$pageName]); + } + + /** + * @return array> + */ + public function getActionList(): array + { + return $this->actions; + } + /** * @param array $newActions + * + * @deprecated since 4.25.0 and it will be removed in EasyAdmin 5.0.0. Use `setPageActions` instead. */ public function setActions(string $pageName, array $newActions): void + { + trigger_deprecation( + 'easycorp/easyadmin-bundle', + '4.25.0', + 'Calling "%s" is deprecated and will be removed in 5.0.0. Use `setPageActions` instead.', + __METHOD__, + ); + + $this->actions[$pageName] = $newActions; + } + + /** + * @param array $newActions + */ + public function setPageActions(string $pageName, array $newActions): void { $this->actions[$pageName] = $newActions; } diff --git a/src/Factory/ActionFactory.php b/src/Factory/ActionFactory.php index bdf8ebcc9f..ba9d5aed52 100644 --- a/src/Factory/ActionFactory.php +++ b/src/Factory/ActionFactory.php @@ -36,7 +36,7 @@ public function processEntityActions(EntityDto $entityDto, ActionConfigDto $acti { $currentPage = $this->adminContextProvider->getContext()->getCrud()->getCurrentPage(); $entityActions = []; - foreach ($actionsDto->getActions()->all() as $actionDto) { + foreach ($actionsDto->getPageActions($currentPage)->all() as $actionDto) { if (!$actionDto->isEntityAction()) { continue; } @@ -79,7 +79,7 @@ public function processGlobalActions(?ActionConfigDto $actionsDto = null): Actio $currentPage = $this->adminContextProvider->getContext()->getCrud()->getCurrentPage(); $globalActions = []; - foreach ($actionsDto->getActions()->all() as $actionDto) { + foreach ($actionsDto->getPageActions($currentPage)->all() as $actionDto) { if (!$actionDto->isGlobalAction() && !$actionDto->isBatchAction()) { continue; } diff --git a/src/Factory/AdminContextFactory.php b/src/Factory/AdminContextFactory.php index f78d9fe0cd..bd91283f9f 100644 --- a/src/Factory/AdminContextFactory.php +++ b/src/Factory/AdminContextFactory.php @@ -132,7 +132,7 @@ private function getCrudDto(CrudControllerRegistry $crudControllers, DashboardCo return $crudDto; } - private function getActionConfig(DashboardControllerInterface $dashboardController, ?CrudControllerInterface $crudController, ?string $pageName): ActionConfigDto + private function getActionConfig(DashboardControllerInterface $dashboardController, ?CrudControllerInterface $crudController, ?string $pageName = null): ActionConfigDto { if (null === $crudController) { return new ActionConfigDto();