add option to remove itetables values and/or specifics keys in the twig toArray function
This commit is contained in:
parent
f9a20716a0
commit
e2c9ecb941
|
@ -1,6 +1,6 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 p-3">
|
<div class="col-md-12 p-3">
|
||||||
{% for item in entity_to_array(entity) %}
|
{% for item in entity_to_array(entity, false, ['id']) %}
|
||||||
<div class="font-weight-bold">{{ item.name|trans }}</div>
|
<div class="font-weight-bold">{{ item.name|trans }}</div>
|
||||||
<div class="mb-3">{{ item.value }}</div>
|
<div class="mb-3">{{ item.value }}</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class EntityExtension extends AbstractExtension
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toArray(EntityInterface $entity): array
|
public function toArray(EntityInterface $entity, bool $keepIterable = true, array $except = []): array
|
||||||
{
|
{
|
||||||
$metaData = $this->entityManager->getClassMetadata(get_class($entity));
|
$metaData = $this->entityManager->getClassMetadata(get_class($entity));
|
||||||
$array = [];
|
$array = [];
|
||||||
|
@ -42,6 +42,14 @@ class EntityExtension extends AbstractExtension
|
||||||
try {
|
try {
|
||||||
$value = $this->propertyAccessor->getValue($entity, $field);
|
$value = $this->propertyAccessor->getValue($entity, $field);
|
||||||
|
|
||||||
|
if (in_array($field, $except)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_iterable($value) && !$keepIterable) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_object($value)) {
|
if (is_object($value)) {
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue