Skip to content

Commit

Permalink
Add Drupal 11 getSupportedTypes on normalizers
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Oct 29, 2024
1 parent 01f5257 commit 8a43ba8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Normalizer/ContentEntityNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
];
}

}
10 changes: 10 additions & 0 deletions src/Normalizer/EntityReferenceItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -178,4 +179,13 @@ public function getUuid($data) {
}
}

/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format): array {
return [
EntityReferenceItem::class => TRUE,
];
}

}
9 changes: 9 additions & 0 deletions src/Normalizer/FieldItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

}
9 changes: 9 additions & 0 deletions src/Normalizer/FieldNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

}
10 changes: 10 additions & 0 deletions src/Normalizer/FileEntityNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
];
}

}

0 comments on commit 8a43ba8

Please sign in to comment.