diff --git a/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractAdminListConfigurator.php b/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractAdminListConfigurator.php index 48d4142622..119e78842a 100644 --- a/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractAdminListConfigurator.php +++ b/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractAdminListConfigurator.php @@ -616,19 +616,27 @@ public function getValue($item, $columnName) public function getStringValue($item, $columnName) { $result = $this->getValue($item, $columnName); + if (\is_bool($result)) { return $result ? 'true' : 'false'; } + if ($result instanceof \DateTimeInterface) { return $result->format('Y-m-d H:i:s'); } if ($result instanceof PersistentCollection) { $results = []; + /* @var Object $entry */ foreach ($result as $entry) { - $results[] = $entry->getName(); + $value = $this->getObjectValue($entry); + + if (!empty($value)) { + $results[] = $value; + } } + if (empty($results)) { return ''; } @@ -643,6 +651,31 @@ public function getStringValue($item, $columnName) return $result; } + /** + * @param object $object + * @return string|null + */ + private function getObjectValue($object) + { + $methods = [ + 'getName', + '__toString', + 'getTitle', + ]; + + foreach ($methods as $method) { + if (method_exists($object, $method)) { + return $object->$method(); + } + } + + if ($object instanceof AbstractEntity) { + return (string) $object->getId(); + } + + return null; + } + /** * @return string */ diff --git a/src/Kunstmaan/AdminListBundle/Controller/AdminListController.php b/src/Kunstmaan/AdminListBundle/Controller/AdminListController.php index c20ebc7c9a..8978f23f27 100644 --- a/src/Kunstmaan/AdminListBundle/Controller/AdminListController.php +++ b/src/Kunstmaan/AdminListBundle/Controller/AdminListController.php @@ -322,10 +322,10 @@ protected function doViewAction(AbstractAdminListConfigurator $configurator, $en throw $this->createAccessDeniedException('You do not have sufficient rights to access this page.'); } - $MetaData = $em->getClassMetadata($configurator->getRepositoryName()); - $fields = array(); + $metaData = $em->getClassMetadata($configurator->getRepositoryName()); + $fields = []; $accessor = PropertyAccess::createPropertyAccessor(); - foreach ($MetaData->fieldNames as $value) { + foreach ($metaData->getReflectionProperties() as $value => $reflectionProperty) { $fields[$value] = $accessor->getValue($helper, $value); } diff --git a/src/Kunstmaan/AdminListBundle/Resources/views/Default/view.html.twig b/src/Kunstmaan/AdminListBundle/Resources/views/Default/view.html.twig index dc52dccefa..f4e2f48b5a 100644 --- a/src/Kunstmaan/AdminListBundle/Resources/views/Default/view.html.twig +++ b/src/Kunstmaan/AdminListBundle/Resources/views/Default/view.html.twig @@ -7,7 +7,7 @@ {% for key, value in fields %} - {{ key }} + {{ key | trans }} {{ adminlistconfigurator.getStringValue(entity, key) }}