From cc8151546af43be68c5e1498abeeb49734f5e16c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 11 Sep 2025 09:40:37 +0200 Subject: [PATCH] Undo inadequate fix of normalizers --- ...PeriodWorkEvaluationDocumentNormalizer.php | 15 ------------- ...mpanyingPeriodWorkEvaluationNormalizer.php | 16 -------------- .../AccompanyingPeriodWorkNormalizer.php | 21 ------------------- 3 files changed, 52 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php index a201e203f..0f08c66c3 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php @@ -29,31 +29,16 @@ class AccompanyingPeriodWorkEvaluationDocumentNormalizer implements \Symfony\Com public function normalize($object, ?string $format = null, array $context = []): array { - // Prevent circular references - $objectHash = spl_object_hash($object); - $visitedKey = 'evaluation_document_visited'; - - if (isset($context[$visitedKey][$objectHash])) { - return [ - 'id' => $object->getId(), - 'type' => 'accompanying_period_work_evaluation_document', - ]; - } - - $context[$visitedKey][$objectHash] = true; - $initial = $this->normalizer->normalize($object, $format, array_merge($context, [ self::SKIP => spl_object_hash($object), ])); $initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor( AccompanyingPeriodWorkEvaluationDocument::class, - $object->getId() ?? 0 ); $workflows = $this->entityWorkflowRepository->findBy([ 'relatedEntityClass' => AccompanyingPeriodWorkEvaluationDocument::class, - 'relatedEntityId' => $object->getId() ?? 0, ]); $initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context); diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php index a8c22d9e0..24b31e86e 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php @@ -33,22 +33,8 @@ class AccompanyingPeriodWorkEvaluationNormalizer implements \Symfony\Component\S */ public function normalize($object, ?string $format = null, array $context = []): array { - // Prevent circular references - $objectHash = spl_object_hash($object); - $visitedKey = 'evaluation_visited'; - - if (isset($context[$visitedKey][$objectHash])) { - return [ - 'id' => $object->getId(), - 'type' => 'accompanying_period_work_evaluation', - ]; - } - - $context[$visitedKey][$objectHash] = true; - $initial = $this->normalizer->normalize($object, $format, array_merge( $context, - [self::IGNORE_EVALUATION => spl_object_hash($object)] )); // due to bug: https://api-platform.com/docs/core/serialization/#collection-relation @@ -64,12 +50,10 @@ class AccompanyingPeriodWorkEvaluationNormalizer implements \Symfony\Component\S $initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor( AccompanyingPeriodWorkEvaluation::class, - $object->getId() ?? 0 ); $workflows = $this->entityWorkflowRepository->findBy([ 'relatedEntityClass' => AccompanyingPeriodWorkEvaluation::class, - 'relatedEntityId' => $object->getId() ?? 0, ]); $initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context); diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php index cd3caa4af..df95b7972 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php @@ -42,25 +42,6 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\ if ('docgen' === $format && !($object instanceof AccompanyingPeriodWork || null === $object)) { throw new UnexpectedValueException(sprintf('Object must be an instanceof AccompanyingPeriodWork or null when format is docgen, %s given', get_debug_type($object))); } - - // Prevent circular references - if ($object instanceof AccompanyingPeriodWork && 'json' === $format) { - $objectHash = spl_object_hash($object); - $visitedKey = 'accompanying_period_work_visited'; - - if (isset($context[$visitedKey][$objectHash])) { - return [ - 'id' => $object->getId(), - 'type' => 'accompanying_period_work', - 'startDate' => $object->getStartDate()?->format('c'), - 'endDate' => $object->getEndDate()?->format('c'), - 'note' => $object->getNote(), - ]; - } - - $context[$visitedKey][$objectHash] = true; - } - $cleanContext = array_filter($context, fn (string|int $key) => !in_array($key, ['docgen:expects', self::IGNORE_WORK], true), ARRAY_FILTER_USE_KEY); if (null === $object && 'docgen' === $format) { @@ -124,7 +105,6 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\ // then, we add normalization for things which are not into the entity $initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor( AccompanyingPeriodWork::class, - $object->getId() ?? 0 ); $initial['workflows_availables_evaluation'] = $this->metadataExtractor->availableWorkflowFor( @@ -137,7 +117,6 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\ $workflows = $this->entityWorkflowRepository->findBy([ 'relatedEntityClass' => AccompanyingPeriodWork::class, - 'relatedEntityId' => $object->getId() ?? 0, ]); $initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);