Skip to content

Commit 306c3b8

Browse files
davidbenatespina
authored andcommitted
Check if entity is array or not to get its value
1 parent 437eb1a commit 306c3b8

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/LIN3S/AdminBundle/Extension/ListField/ActionsListFieldType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function render($entity, $options, Entity $configuration)
8989

9090
$url = $this->urlGenerator->generate('lin3s_admin_custom', [
9191
'entity' => $configuration->name(),
92-
'id' => $entity->id(),
92+
'id' => is_array($entity)? $entity['id'] : $entity->id(),
9393
'action' => $action->name(),
9494
]);
9595

src/LIN3S/AdminBundle/Extension/ListField/DateListFieldType.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ public function render($entity, $options, Entity $configuration)
6060
throw new \InvalidArgumentException('Field to be rendered must be passed as string');
6161
}
6262

63-
$properties = explode('.', $options['field']);
64-
65-
$value = $entity;
66-
foreach ($properties as $property) {
67-
$value = $value->$property();
63+
if (is_array($entity)) {
64+
$value = new \DateTimeImmutable($entity[$options['field']]);
65+
} else {
66+
$properties = explode('.', $options['field']);
67+
$value = $entity;
68+
foreach ($properties as $property) {
69+
$value = $value->$property();
70+
}
6871
}
72+
6973
if (null === $value) {
7074
return $this->translator->trans('lin3s_admin.list.field_type.date.not_available');
7175
}

src/LIN3S/AdminBundle/Extension/ListField/StringListFieldType.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ public function render($entity, $options, Entity $configuration)
4141
if (!isset($options['field'])) {
4242
throw new \InvalidArgumentException('Field to be rendered must be passed as string');
4343
}
44-
$properties = explode('.', $options['field']);
4544

46-
$value = $entity;
47-
foreach ($properties as $property) {
48-
$value = $value->$property();
45+
if (is_array($entity)) {
46+
$value = $entity[$options['field']];
47+
} else {
48+
$properties = explode('.', $options['field']);
49+
$value = $entity;
50+
foreach ($properties as $property) {
51+
$value = $value->$property();
52+
}
4953
}
5054

5155
return $this->translator->trans($value);

0 commit comments

Comments
 (0)