diff --git a/doc/fields.rst b/doc/fields.rst index d46e60fc19..4e55544114 100644 --- a/doc/fields.rst +++ b/doc/fields.rst @@ -556,6 +556,12 @@ Design Options // (this is not used in the 'edit'/'new' pages because they use Symfony Forms themes) ->setTemplatePath('admin/fields/my_template.html.twig') + // if you need to access custom twig variables setted via call to CrudController::configureResponseParameters + ->setWithTwigContext(true) + + // Display field as full-width, remove completly dt,dd tags and label + ->setFullWidth(true) + // useful for example to right-align numbers/money values (this setting is ignored in 'detail' page) ->setTextAlign('right') ; diff --git a/src/Dto/FieldDto.php b/src/Dto/FieldDto.php index 23e916ffce..5921a2338c 100644 --- a/src/Dto/FieldDto.php +++ b/src/Dto/FieldDto.php @@ -26,6 +26,8 @@ final class FieldDto private ?string $permission = null; private ?string $textAlign = null; private $help; + private bool $fullWidth = false; + private bool $withTwigContext = false; private string $cssClass = ''; // how many columns the field takes when rendering // (defined as Bootstrap 5 grid classes; e.g. 'col-md-6 col-xxl-3') @@ -262,6 +264,30 @@ public function setHelp(TranslatableInterface|string $help): void $this->help = $help; } + public function setFullWidth(bool $fullWidth = true): self + { + $this->fullWidth = $fullWidth; + + return $this; + } + + public function getFullWidth(): bool + { + return $this->fullWidth; + } + + public function setWithTwigContext(bool $withTwigContext = true): self + { + $this->withTwigContext = $withTwigContext; + + return $this; + } + + public function getWithTwigContext(): bool + { + return $this->withTwigContext; + } + public function getCssClass(): string { return $this->cssClass; diff --git a/src/Field/FieldTrait.php b/src/Field/FieldTrait.php index b1c001a42c..be543a7728 100644 --- a/src/Field/FieldTrait.php +++ b/src/Field/FieldTrait.php @@ -165,6 +165,20 @@ public function setHelp(TranslatableInterface|string $help): self return $this; } + public function setFullWidth(bool $fullWidth = true): self + { + $this->dto->setFullWidth($fullWidth); + + return $this; + } + + public function setWithTwigContext(bool $withTwigContext = true): self + { + $this->dto->setWithTwigContext($withTwigContext); + + return $this; + } + public function addCssClass(string $cssClass): self { $this->dto->setCssClass($this->dto->getCssClass().' '.$cssClass); diff --git a/src/Resources/views/crud/detail.html.twig b/src/Resources/views/crud/detail.html.twig index f605c9546c..5fc7744c7c 100644 --- a/src/Resources/views/crud/detail.html.twig +++ b/src/Resources/views/crud/detail.html.twig @@ -54,9 +54,9 @@ {% set field_layout = ea_create_field_layout(entity.fields) %} {% block detail_fields %} {% if field_layout.hasTabs %} - {{ _self.render_detail_fields_with_tabs(entity, field_layout) }} + {{ _self.render_detail_fields_with_tabs(entity, field_layout, _context) }} {% else %} - {{ _self.render_detail_fields(entity, field_layout.fields) }} + {{ _self.render_detail_fields(entity, field_layout.fields, _context) }} {% endif %} {% endblock detail_fields %} @@ -65,7 +65,7 @@ {% endblock delete_form %} {% endblock %} -{% macro render_detail_fields_with_tabs(entity, field_layout) %} +{% macro render_detail_fields_with_tabs(entity, field_layout, variables) %}