Skip to content

Commit 16e13c4

Browse files
Deprecate getActions
1 parent 69a92e3 commit 16e13c4

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

src/Config/Actions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function remove(string $pageName, string $actionName): self
8181
public function reorder(string $pageName, array $orderedActionNames): self
8282
{
8383
$newActionOrder = [];
84-
$currentActions = $this->dto->getActions();
84+
$currentActions = $this->dto->getActionList();
8585
foreach ($orderedActionNames as $actionName) {
8686
if (!\array_key_exists($actionName, $currentActions[$pageName])) {
8787
throw new \InvalidArgumentException(sprintf('The "%s" action does not exist in the "%s" page, so you cannot set its order.', $actionName, $pageName));

src/Dto/ActionConfigDto.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public function __clone()
3939
}
4040
}
4141

42+
/**
43+
* @deprecated since 4.25.0 and it will be removed in EasyAdmin 5.0.0.
44+
*/
4245
public function setPageName(?string $pageName): void
4346
{
4447
$this->pageName = $pageName;
@@ -109,16 +112,55 @@ public function disableActions(array $actionNames): void
109112

110113
/**
111114
* @return ActionCollection|array<string,array<string,ActionDto>>
115+
*
116+
* @deprecated since 4.25.0 and it will be removed in EasyAdmin 5.0.0. Use `getPageActions` or `getActionList` instead.
112117
*/
113118
public function getActions(): ActionCollection|array
114119
{
120+
trigger_deprecation(
121+
'easycorp/easyadmin-bundle',
122+
'4.25.0',
123+
'Calling "%s" is deprecated and will be removed in 5.0.0. Use `getPageActions` or `getActionList` instead.',
124+
__METHOD__,
125+
);
126+
115127
return null === $this->pageName ? $this->actions : ActionCollection::new($this->actions[$this->pageName]);
116128
}
117129

130+
public function getPageActions(string $pageName): ActionCollection
131+
{
132+
return ActionCollection::new($this->actions[$pageName]);
133+
}
134+
135+
/**
136+
* @return array<string,array<string,ActionDto>>
137+
*/
138+
public function getActionList(): array
139+
{
140+
return $this->actions;
141+
}
142+
118143
/**
119144
* @param array<string, ActionDto> $newActions
145+
*
146+
* @deprecated since 4.25.0 and it will be removed in EasyAdmin 5.0.0. Use `setPageActions` instead.
120147
*/
121148
public function setActions(string $pageName, array $newActions): void
149+
{
150+
trigger_deprecation(
151+
'easycorp/easyadmin-bundle',
152+
'4.25.0',
153+
'Calling "%s" is deprecated and will be removed in 5.0.0. Use `setPageActions` instead.',
154+
__METHOD__,
155+
);
156+
157+
$this->actions[$pageName] = $newActions;
158+
}
159+
160+
/**
161+
* @param array<string, ActionDto> $newActions
162+
*/
163+
public function setPageActions(string $pageName, array $newActions): void
122164
{
123165
$this->actions[$pageName] = $newActions;
124166
}

src/Factory/ActionFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function processEntityActions(EntityDto $entityDto, ActionConfigDto $acti
3636
{
3737
$currentPage = $this->adminContextProvider->getContext()->getCrud()->getCurrentPage();
3838
$entityActions = [];
39-
foreach ($actionsDto->getActions()->all() as $actionDto) {
39+
foreach ($actionsDto->getPageActions($currentPage)->all() as $actionDto) {
4040
if (!$actionDto->isEntityAction()) {
4141
continue;
4242
}
@@ -79,7 +79,7 @@ public function processGlobalActions(?ActionConfigDto $actionsDto = null): Actio
7979

8080
$currentPage = $this->adminContextProvider->getContext()->getCrud()->getCurrentPage();
8181
$globalActions = [];
82-
foreach ($actionsDto->getActions()->all() as $actionDto) {
82+
foreach ($actionsDto->getPageActions($currentPage)->all() as $actionDto) {
8383
if (!$actionDto->isGlobalAction() && !$actionDto->isBatchAction()) {
8484
continue;
8585
}

src/Factory/AdminContextFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function getCrudDto(CrudControllerRegistry $crudControllers, DashboardCo
132132
return $crudDto;
133133
}
134134

135-
private function getActionConfig(DashboardControllerInterface $dashboardController, ?CrudControllerInterface $crudController, ?string $pageName): ActionConfigDto
135+
private function getActionConfig(DashboardControllerInterface $dashboardController, ?CrudControllerInterface $crudController, ?string $pageName = null): ActionConfigDto
136136
{
137137
if (null === $crudController) {
138138
return new ActionConfigDto();

0 commit comments

Comments
 (0)