diff --git a/core/Crud/CrudConfiguration.php b/core/Crud/CrudConfiguration.php index 7206c52..ed67a3d 100644 --- a/core/Crud/CrudConfiguration.php +++ b/core/Crud/CrudConfiguration.php @@ -16,9 +16,21 @@ class CrudConfiguration protected array $forms = []; protected array $formOptions = []; protected array $views = []; + protected array $viewDatas = []; protected array $fields = []; protected array $maxPerPage = []; + protected static $self; + + public function create() + { + if (null === self::$self) { + self::$self = new self(); + } + + return self::$self; + } + /* -- */ public function setPageTitle(string $page, string $title): self @@ -127,6 +139,31 @@ class CrudConfiguration return $this->views[$context] ?? $default; } + public function addViewData(string $context, string $name, $value): self + { + if (!isset($this->viewDatas[$context])) { + $this->viewDatas[$context] = []; + } + + $this->viewDatas[$context][$name] = $value; + + return $this; + } + + public function setViewDatas(string $context, array $datas): self + { + foreach ($datas as $name => $value) { + $this->addViewData($name, $value); + } + + return $this; + } + + public function getViewDatas(string $context): array + { + return $this->viewDatas[$context] ?? []; + } + /* -- */ public function setField(string $context, string $label, string $field, array $options): self diff --git a/core/Crud/Field/Field.php b/core/Crud/Field/Field.php index 70a8049..165951c 100644 --- a/core/Crud/Field/Field.php +++ b/core/Crud/Field/Field.php @@ -28,6 +28,7 @@ abstract class Field 'property' => null, 'property_builder' => null, 'view' => null, + 'raw' => false, 'attr' => [], ]); @@ -35,6 +36,7 @@ abstract class Field $resolver->setAllowedTypes('property', ['null', 'string']); $resolver->setAllowedTypes('view', 'string'); $resolver->setAllowedTypes('attr', 'array'); + $resolver->setAllowedTypes('raw', 'boolean'); $resolver->setAllowedTypes('property_builder', ['null', 'callable']); return $resolver; diff --git a/core/Resources/views/admin/crud/field/button.html.twig b/core/Resources/views/admin/crud/field/button.html.twig index ab9cb02..f832707 100644 --- a/core/Resources/views/admin/crud/field/button.html.twig +++ b/core/Resources/views/admin/crud/field/button.html.twig @@ -1 +1 @@ -<{{ options.button_tag }} {% for k, v in options.button_attr %}{{ k }}="{{ v }}"{% endfor %}>{{ value }} +<{{ options.button_tag }} {% for k, v in options.button_attr %}{{ k }}="{{ v }}"{% endfor %}>{% if options.raw %}{{ value|raw }}{% else %}{{ value }}{% endif %} diff --git a/core/Resources/views/admin/crud/field/text.html.twig b/core/Resources/views/admin/crud/field/text.html.twig index 40cf72a..a274c49 100644 --- a/core/Resources/views/admin/crud/field/text.html.twig +++ b/core/Resources/views/admin/crud/field/text.html.twig @@ -1 +1,2 @@ -{{ value }} +{% if options.raw %}{{ value|raw }}{% else %}{{ value }}{% endif %} + diff --git a/core/Resources/views/admin/crud/index.html.twig b/core/Resources/views/admin/crud/index.html.twig index 315bbb9..af73b81 100644 --- a/core/Resources/views/admin/crud/index.html.twig +++ b/core/Resources/views/admin/crud/index.html.twig @@ -85,8 +85,14 @@ {% endfor %} - {% if configuration.action('index', 'edit', true) or configuration.action('index', 'delete', true) %} + {% if configuration.action('index', 'show', true) or configuration.action('index', 'edit', true) or configuration.action('index', 'delete', true) %} + {% if configuration.action('index', 'show', true) %} + + + + {% endif %} + {% if configuration.action('index', 'edit', true) %}