add view datas; add raw option in field

This commit is contained in:
Simon Vieille 2021-05-12 12:44:36 +02:00
parent f47bcfffc6
commit 329405801f
5 changed files with 49 additions and 3 deletions

View file

@ -16,9 +16,21 @@ class CrudConfiguration
protected array $forms = []; protected array $forms = [];
protected array $formOptions = []; protected array $formOptions = [];
protected array $views = []; protected array $views = [];
protected array $viewDatas = [];
protected array $fields = []; protected array $fields = [];
protected array $maxPerPage = []; 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 public function setPageTitle(string $page, string $title): self
@ -127,6 +139,31 @@ class CrudConfiguration
return $this->views[$context] ?? $default; 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 public function setField(string $context, string $label, string $field, array $options): self

View file

@ -28,6 +28,7 @@ abstract class Field
'property' => null, 'property' => null,
'property_builder' => null, 'property_builder' => null,
'view' => null, 'view' => null,
'raw' => false,
'attr' => [], 'attr' => [],
]); ]);
@ -35,6 +36,7 @@ abstract class Field
$resolver->setAllowedTypes('property', ['null', 'string']); $resolver->setAllowedTypes('property', ['null', 'string']);
$resolver->setAllowedTypes('view', 'string'); $resolver->setAllowedTypes('view', 'string');
$resolver->setAllowedTypes('attr', 'array'); $resolver->setAllowedTypes('attr', 'array');
$resolver->setAllowedTypes('raw', 'boolean');
$resolver->setAllowedTypes('property_builder', ['null', 'callable']); $resolver->setAllowedTypes('property_builder', ['null', 'callable']);
return $resolver; return $resolver;

View file

@ -1 +1 @@
<{{ options.button_tag }} {% for k, v in options.button_attr %}{{ k }}="{{ v }}"{% endfor %}>{{ value }}</{{ options.button_tag }}> <{{ options.button_tag }} {% for k, v in options.button_attr %}{{ k }}="{{ v }}"{% endfor %}>{% if options.raw %}{{ value|raw }}{% else %}{{ value }}{% endif %}</{{ options.button_tag }}>

View file

@ -1 +1,2 @@
{{ value }} {% if options.raw %}{{ value|raw }}{% else %}{{ value }}{% endif %}

View file

@ -85,8 +85,14 @@
</td> </td>
{% endfor %} {% 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) %}
<td class="col-2 miw-100 text-right"> <td class="col-2 miw-100 text-right">
{% if configuration.action('index', 'show', true) %}
<a href="{{ path(configuration.pageRoute('show'), {entity: item.id}) }}" class="btn btn-sm btn-secondary mr-1">
<span class="fa fa-eye"></span>
</a>
{% endif %}
{% if configuration.action('index', 'edit', true) %} {% if configuration.action('index', 'edit', true) %}
<a href="{{ path(configuration.pageRoute('edit'), {entity: item.id}) }}" class="btn btn-sm btn-primary mr-1"> <a href="{{ path(configuration.pageRoute('edit'), {entity: item.id}) }}" class="btn btn-sm btn-primary mr-1">
<span class="fa fa-edit"></span> <span class="fa fa-edit"></span>