diff --git a/src/Bundle/ChillMainBundle/Export/ExportDataNormalizerTrait.php b/src/Bundle/ChillMainBundle/Export/ExportDataNormalizerTrait.php index 9dafd597b..44cdc8310 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportDataNormalizerTrait.php +++ b/src/Bundle/ChillMainBundle/Export/ExportDataNormalizerTrait.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Export; +use Doctrine\Common\Collections\Collection; use Doctrine\Persistence\ObjectRepository; trait ExportDataNormalizerTrait @@ -21,10 +22,13 @@ trait ExportDataNormalizerTrait public function normalizeDoctrineEntity(object|array $entity): array|int { if (is_array($entity)) { - return array_values(array_map(static fn (object $entity) => $entity->getId(), $entity)); + return array_values(array_filter(array_map(static fn (object $entity) => $entity->getId(), $entity), fn ($value) => null !== $value)); + } + if ($entity instanceof Collection) { + return $this->normalizeDoctrineEntity($entity->toArray()); } - return $entity->getId(); + return $entity?->getId(); } public function denormalizeDoctrineEntity(array|int $id, ObjectRepository $repository): object|array