From 8a43ba88c29e8d896c97b7cb10a1daa8c6ebb0f3 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Tue, 29 Oct 2024 11:21:23 -0400 Subject: [PATCH] Add Drupal 11 getSupportedTypes on normalizers --- src/Normalizer/ContentEntityNormalizer.php | 10 ++++++++++ src/Normalizer/EntityReferenceItemNormalizer.php | 10 ++++++++++ src/Normalizer/FieldItemNormalizer.php | 9 +++++++++ src/Normalizer/FieldNormalizer.php | 9 +++++++++ src/Normalizer/FileEntityNormalizer.php | 10 ++++++++++ 5 files changed, 48 insertions(+) diff --git a/src/Normalizer/ContentEntityNormalizer.php b/src/Normalizer/ContentEntityNormalizer.php index 55ffa10..c1b4834 100644 --- a/src/Normalizer/ContentEntityNormalizer.php +++ b/src/Normalizer/ContentEntityNormalizer.php @@ -3,6 +3,7 @@ namespace Drupal\jsonld\Normalizer; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\hal\LinkManager\LinkManagerInterface; @@ -304,4 +305,13 @@ protected function getTypedDataIds(array $types, array $context = []) { return $typed_data_ids; } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + ContentEntityInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/EntityReferenceItemNormalizer.php b/src/Normalizer/EntityReferenceItemNormalizer.php index 2646a40..85c4256 100644 --- a/src/Normalizer/EntityReferenceItemNormalizer.php +++ b/src/Normalizer/EntityReferenceItemNormalizer.php @@ -3,6 +3,7 @@ namespace Drupal\jsonld\Normalizer; use Drupal\Core\Entity\FieldableEntityInterface; +use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\hal\LinkManager\LinkManagerInterface; use Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface; use Drupal\serialization\EntityResolver\EntityResolverInterface; @@ -178,4 +179,13 @@ public function getUuid($data) { } } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + EntityReferenceItem::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/FieldItemNormalizer.php b/src/Normalizer/FieldItemNormalizer.php index 1922297..be0004d 100644 --- a/src/Normalizer/FieldItemNormalizer.php +++ b/src/Normalizer/FieldItemNormalizer.php @@ -210,4 +210,13 @@ protected function createTranslatedInstance(FieldItemInterface $item, $langcode) return $entity_translation->get($field_name)->appendItem(); } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + FieldItemInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/FieldNormalizer.php b/src/Normalizer/FieldNormalizer.php index 96153c3..ad58d1e 100644 --- a/src/Normalizer/FieldNormalizer.php +++ b/src/Normalizer/FieldNormalizer.php @@ -110,4 +110,13 @@ protected function normalizeFieldItems(FieldItemListInterface $field, $format, a return $normalized_field_items; } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + FieldItemListInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/FileEntityNormalizer.php b/src/Normalizer/FileEntityNormalizer.php index 9d7cc74..6ea53d2 100644 --- a/src/Normalizer/FileEntityNormalizer.php +++ b/src/Normalizer/FileEntityNormalizer.php @@ -5,6 +5,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\File\FileSystemInterface; +use Drupal\file\FileInterface; use Drupal\hal\LinkManager\LinkManagerInterface; use Drupal\jsonld\Utils\JsonldNormalizerUtilsInterface; use GuzzleHttp\ClientInterface; @@ -89,4 +90,13 @@ public function denormalize(mixed $data, string $class, ?string $format = NULL, return $this->entityManager->getStorage('file')->create($data); } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + FileInterface::class => TRUE, + ]; + } + }