Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to append or prepend action #5471

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from
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
18 changes: 9 additions & 9 deletions src/Config/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ public static function new(): self
return new self($dto);
}

public function add(string $pageName, Action|string $actionNameOrObject): self
public function add(string $pageName, Action|string $actionNameOrObject, bool $isAppend = false): self
{
return $this->doAddAction($pageName, $actionNameOrObject);
return $this->doAddAction($pageName, $actionNameOrObject, false, $isAppend);
}

public function addBatchAction(Action|string $actionNameOrObject): self
public function addBatchAction(Action|string $actionNameOrObject, bool $isAppend = false): self
{
return $this->doAddAction(Crud::PAGE_INDEX, $actionNameOrObject, true);
return $this->doAddAction(Crud::PAGE_INDEX, $actionNameOrObject, true, $isAppend);
}

public function set(string $pageName, Action|string $actionNameOrObject): self
{
$action = \is_string($actionNameOrObject) ? $this->createBuiltInAction($pageName, $actionNameOrObject) : $actionNameOrObject;

$this->dto->appendAction($pageName, $action->getAsDto());
$this->dto->prependAction($pageName, $action->getAsDto());

return $this;
}
Expand Down Expand Up @@ -219,7 +219,7 @@ private function createBuiltInAction(string $pageName, string $actionName): Acti
throw new \InvalidArgumentException(sprintf('The "%s" action is not a built-in action, so you can\'t add or configure it via its name. Either refer to one of the built-in actions or create a custom action called "%s".', $actionName, $actionName));
}

private function doAddAction(string $pageName, Action|string $actionNameOrObject, bool $isBatchAction = false): self
private function doAddAction(string $pageName, Action|string $actionNameOrObject, bool $isBatchAction = false, bool $isAppend = false): self
{
$actionName = \is_string($actionNameOrObject) ? $actionNameOrObject : (string) $actionNameOrObject;
$action = \is_string($actionNameOrObject) ? $this->createBuiltInAction($pageName, $actionNameOrObject) : $actionNameOrObject;
Expand All @@ -233,10 +233,10 @@ private function doAddAction(string $pageName, Action|string $actionNameOrObject
$actionDto->setType(Action::TYPE_BATCH);
}

if (Crud::PAGE_INDEX === $pageName && Action::DELETE === $actionName) {
$this->dto->prependAction($pageName, $actionDto);
} else {
if ((Crud::PAGE_INDEX === $pageName && Action::DELETE === $actionName) || $isAppend) {
$this->dto->appendAction($pageName, $actionDto);
} else {
$this->dto->prependAction($pageName, $actionDto);
}

return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Dto/ActionConfigDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public function setActionPermissions(array $permissions): void

public function prependAction(string $pageName, ActionDto $actionDto): void
{
$this->actions[$pageName][$actionDto->getName()] = $actionDto;
$this->actions[$pageName] = array_merge([$actionDto->getName() => $actionDto], $this->actions[$pageName]);
}

public function appendAction(string $pageName, ActionDto $actionDto): void
{
$this->actions[$pageName] = array_merge([$actionDto->getName() => $actionDto], $this->actions[$pageName]);
$this->actions[$pageName] = array_merge($this->actions[$pageName], [$actionDto->getName() => $actionDto]);
}

public function setAction(string $pageName, ActionDto $actionDto): void
Expand Down