registry = $registry; $this->entityWorkflowRepository = $entityWorkflowRepository; $this->metadataExtractor = $metadataExtractor; } /** * @param AccompanyingPeriodWorkEvaluation $object */ public function normalize($object, ?string $format = null, array $context = []): array { $initial = $this->normalizer->normalize($object, $format, array_merge( $context, [self::IGNORE_EVALUATION => spl_object_hash($object)], [AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER => static function ($object, $format, $context) { return $object->getId(); }] )); // due to bug: https://api-platform.com/docs/core/serialization/#collection-relation // and also: https://github.com/symfony/symfony/issues/36965 // we have to rewrite the documents as a collection $initial['documents'] = $this->normalizer->normalize( $object->getDocuments()->getValues(), $format, $context ); // then, we add normalization for things which are not into the entity $initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor( AccompanyingPeriodWorkEvaluation::class, $object->getId() ); $workflows = $this->entityWorkflowRepository->findBy([ 'relatedEntityClass' => AccompanyingPeriodWorkEvaluation::class, 'relatedEntityId' => $object->getId(), ]); $initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context); return $initial; } public function supportsNormalization($data, ?string $format = null, array $context = []): bool { return 'json' === $format && $data instanceof AccompanyingPeriodWorkEvaluation && !array_key_exists(self::IGNORE_EVALUATION, $context); } }