thirdPartyRender = $thirdPartyRender; $this->translatableStringHelper = $translatableStringHelper; } /** * @param ThirdParty $thirdParty * @param string|null $format */ public function normalize($thirdParty, $format = null, array $context = []) { return [ 'type' => 'thirdparty', 'name' => $thirdParty->getName(), 'text' => $this->thirdPartyRender->renderString($thirdParty, []), 'id' => $thirdParty->getId(), 'kind' => $thirdParty->getKind(), 'category' => array_map(function ($el) { if ($el instanceof ThirdPartyCategory) { return [ 'text' => $this->translatableStringHelper->localize($el->getName()), 'type' => 'thirdparty_category', ]; } return [ 'text' => $el, 'type' => 'thirdparty_kind', ]; }, $thirdParty->getTypesAndCategories()), 'profession' => $this->normalizer->normalize($thirdParty->getProfession(), $format, $context), 'address' => $this->normalizer->normalize($thirdParty->getAddress(), $format, ['address_rendering' => 'short']), 'telephone' => $this->normalizer->normalize($thirdParty->getTelephone()), 'email' => $thirdParty->getEmail(), 'isChild' => $thirdParty->isChild(), 'parent' => $this->normalizer->normalize($thirdParty->getParent(), $format, $context), 'civility' => $this->normalizer->normalize($thirdParty->getCivility(), $format, $context), 'contactDataAnonymous' => $thirdParty->isContactDataAnonymous(), ]; } public function supportsNormalization($data, $format = null) { return $data instanceof ThirdParty && 'json' === $format; } }