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
5 changes: 5 additions & 0 deletions assets/css/easyadmin-theme/detail-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
min-inline-size: 66%;
}

.ea-detail .field-group .field-actions {
flex: 1;
min-inline-size: 66%;
}

.ea-detail .field-group.field-textarea .field-value,
.ea-detail .field-group.field-text_editor .field-value {
max-block-size: 350px;
Expand Down
10 changes: 7 additions & 3 deletions src/Config/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public static function new(): self
return new self($dto);
}

public function add(string $pageName, Action|ActionGroup|string $actionNameOrObject): self
public function add(string $pageName, Action|ActionGroup|string $actionNameOrObject, ?string $property = null): self
{
if ($actionNameOrObject instanceof ActionGroup) {
$this->dto->appendAction($pageName, $actionNameOrObject->getAsDto());

return $this;
}

return $this->doAddAction($pageName, $actionNameOrObject);
return $this->doAddAction($pageName, $actionNameOrObject, false, $property);
}

public function addBatchAction(Action|string $actionNameOrObject): self
Expand Down Expand Up @@ -225,7 +225,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, ?string $property = null): self
{
$actionName = \is_string($actionNameOrObject) ? $actionNameOrObject : (string) $actionNameOrObject;
$action = \is_string($actionNameOrObject) ? $this->createBuiltInAction($pageName, $actionNameOrObject) : $actionNameOrObject;
Expand All @@ -239,6 +239,10 @@ private function doAddAction(string $pageName, Action|string $actionNameOrObject
$actionDto->setType(Action::TYPE_BATCH);
}

if (Crud::PAGE_DETAIL === $pageName) {
$actionDto->setProperty($property);
}

$this->dto->appendAction($pageName, $actionDto);

return $this;
Expand Down
12 changes: 12 additions & 0 deletions src/Dto/ActionDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ final class ActionDto
private array $translationParameters = [];
/** @var callable|null */
private $displayCallable;
private ?string $property = null;
private ButtonElement $htmlElement = ButtonElement::Button;
private ButtonType $butonType = ButtonType::Submit;
private ButtonVariant $variant = ButtonVariant::Default;
private ButtonStyle $style = ButtonStyle::Solid;
private ?string $property = null;

public function getType(): string
{
Expand Down Expand Up @@ -408,4 +410,14 @@ public function getAsConfigObject(): Action

return $action;
}

public function getProperty(): ?string
{
return $this->property;
}

public function setProperty(?string $property): void
{
$this->property = $property;
}
}
12 changes: 12 additions & 0 deletions src/Dto/FieldDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EasyCorp\Bundle\EasyAdminBundle\Dto;

use EasyCorp\Bundle\EasyAdminBundle\Collection\ActionCollection;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\EaFormFieldsetType;
Expand Down Expand Up @@ -66,6 +67,7 @@ final class FieldDto
private KeyValueStore $displayedOn;
/** @var array<string, bool|int|float|string> */
private array $htmlAttributes = [];
private ?ActionCollection $actions = null;

public function __construct()
{
Expand Down Expand Up @@ -560,4 +562,14 @@ public function setHtmlAttribute(string $attribute, mixed $value): self

return $this;
}

public function getActions(): ?ActionCollection
{
return $this->actions;
}

public function setActions(?ActionCollection $actions): void
{
$this->actions = $actions;
}
}
14 changes: 13 additions & 1 deletion src/Factory/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function processEntityActions(EntityDto $entityDto, ActionConfigDto $acti
$currentPage = $this->adminContextProvider->getContext()->getCrud()->getCurrentPage();
$processedItems = [];

$propertyActions = [];
foreach ($actionsDto->getActions()->all() as $item) {
if ($item instanceof ActionDto) {
if (!$item->isEntityAction()) {
Expand All @@ -67,7 +68,15 @@ public function processEntityActions(EntityDto $entityDto, ActionConfigDto $acti
$item->setCssClass($item->getCssClass().' '.$addedCssClass);
}

$processedItems[$item->getName()] = $this->processAction($currentPage, $item, $entityDto);

if (null === $item->getProperty()) {
$processedItems[$item->getName()] = $this->processAction($currentPage, $item, $entityDto);
} else {
if (!isset($propertyActions[$item->getProperty()])) {
$propertyActions[$item->getProperty()] = [];
}
$propertyActions[$item->getProperty()][$item->getName()] = $this->processAction($currentPage, $item, $entityDto);
}
} elseif ($item instanceof ActionGroupDto) {
if (!$item->isEntityAction()) {
continue;
Expand All @@ -91,6 +100,9 @@ public function processEntityActions(EntityDto $entityDto, ActionConfigDto $acti
}

$entityDto->setActions(ActionCollection::new($processedItems));
foreach ($propertyActions as $property => $actions) {
$entityDto->getFields()->getByProperty($property)?->setActions(ActionCollection::new($actions));
}
}

public function processGlobalActions(?ActionConfigDto $actionsDto = null): ActionCollection
Expand Down
14 changes: 12 additions & 2 deletions templates/crud/detail.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,18 @@
</div>
{% endif %}

<div class="field-value">
{{ include(field.templatePath, { field: field, entity: entity }, with_context = false) }}
<div>
<div class="field-value">
{{ include(field.templatePath, { field: field, entity: entity }, with_context = false) }}
</div>

{% if field.actions is not null %}
<div class="field-actions">
{% for action in field.actions %}
{{ include(action.templatePath, { action: action }, with_context = false) }}
{% endfor %}
</div>
{% endif %}
</div>
</div>
{% endmacro %}
Expand Down