diff --git a/src/Config/Actions.php b/src/Config/Actions.php index 50e587719a..e54b54ac09 100644 --- a/src/Config/Actions.php +++ b/src/Config/Actions.php @@ -55,7 +55,7 @@ public function update(string $pageName, string $actionName, callable $callable) $action = $actionDto->getAsConfigObject(); - /** @var Action $action */ + /** @var Action|ActionGroup $action */ $action = $callable($action); $this->dto->setAction($pageName, $action->getAsDto()); diff --git a/src/Dto/ActionGroupDto.php b/src/Dto/ActionGroupDto.php index 086ec9ebdd..37c19e76c8 100644 --- a/src/Dto/ActionGroupDto.php +++ b/src/Dto/ActionGroupDto.php @@ -272,4 +272,41 @@ public function setHasAnyActionWithIcon(bool $hasAnyActionWithIcon): void { $this->hasAnyActionWithIcon = $hasAnyActionWithIcon; } + + public function getAsConfigObject(): ActionGroup + { + $action = ActionGroup::new($this->name, $this->label, $this->icon); + $action->setCssClass($this->cssClass); + $action->addCssClass($this->addedCssClass); + $action->setHtmlAttributes($this->htmlAttributes); + $action->setHtmlAttributes($this->htmlAttributes); + + if (null !== $this->templatePath) { + $action->setTemplatePath($this->templatePath); + } + + if ($this->isGlobalAction()) { + $action->createAsGlobalActionGroup(); + } + + if (null !== $this->mainAction) { + $action->addMainAction($this->mainAction->getAsConfigObject()); + } + + foreach ($this->items as $index => $item) { + if ($item instanceof ActionDto) { + $action->addAction($item->getAsConfigObject()); + } elseif ('divider' === ($item['type'] ?? null)) { + $action->addDivider(); + } elseif ('header' === ($item['type'] ?? null)) { + $action->addHeader($item['content']); + } + } + + if (null !== $this->displayCallable) { + $action->displayIf($this->displayCallable); + } + + return $action; + } }