add view datas; add raw option in field
This commit is contained in:
parent
f47bcfffc6
commit
329405801f
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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 }}>
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
{{ value }}
|
{% if options.raw %}{{ value|raw }}{% else %}{{ value }}{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue