Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Config/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
42 changes: 42 additions & 0 deletions src/Dto/ActionConfigDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,16 +112,55 @@ public function disableActions(array $actionNames): void

/**
* @return ActionCollection|array<string,array<string,ActionDto>>
*
* @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<string,array<string,ActionDto>>
*/
public function getActionList(): array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAllActions() instead of getActionList()?

Suggested change
public function getActionList(): array
public function getAllActions(): array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, indeed not a bad idea.

I'm waiting for an opinion from javiereguiluz on this

{
return $this->actions;
}

/**
* @param array<string, ActionDto> $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<string, ActionDto> $newActions
*/
public function setPageActions(string $pageName, array $newActions): void
{
$this->actions[$pageName] = $newActions;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/AdminContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down