UuidResolver.php in Drupal 10
File
core/modules/serialization/src/EntityResolver/UuidResolver.php
View source
<?php
namespace Drupal\serialization\EntityResolver;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class UuidResolver implements EntityResolverInterface {
protected $entityRepository;
public function __construct(EntityRepositoryInterface $entity_repository) {
$this->entityRepository = $entity_repository;
}
public function resolve(NormalizerInterface $normalizer, $data, $entity_type) {
if ($normalizer instanceof UuidReferenceInterface && ($uuid = $normalizer
->getUuid($data))) {
if ($entity = $this->entityRepository
->loadEntityByUuid($entity_type, $uuid)) {
return $entity
->id();
}
}
return NULL;
}
}
Classes
Name |
Description |
UuidResolver |
Resolves entities from data that contains an entity UUID. |