class UuidResolver in Drupal 10
Same name and namespace in other branches
- 8 core/modules/serialization/src/EntityResolver/UuidResolver.php \Drupal\serialization\EntityResolver\UuidResolver
- 9 core/modules/serialization/src/EntityResolver/UuidResolver.php \Drupal\serialization\EntityResolver\UuidResolver
Resolves entities from data that contains an entity UUID.
Hierarchy
- class \Drupal\serialization\EntityResolver\UuidResolver implements EntityResolverInterface
Expanded class hierarchy of UuidResolver
1 file declares its use of UuidResolver
- UuidResolverTest.php in core/
modules/ serialization/ tests/ src/ Unit/ EntityResolver/ UuidResolverTest.php
1 string reference to 'UuidResolver'
- serialization.services.yml in core/
modules/ serialization/ serialization.services.yml - core/modules/serialization/serialization.services.yml
1 service uses UuidResolver
- serializer.entity_resolver.uuid in core/
modules/ serialization/ serialization.services.yml - Drupal\serialization\EntityResolver\UuidResolver
File
- core/
modules/ serialization/ src/ EntityResolver/ UuidResolver.php, line 11
Namespace
Drupal\serialization\EntityResolverView source
class UuidResolver implements EntityResolverInterface {
/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* Constructs a UuidResolver object.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
*/
public function __construct(EntityRepositoryInterface $entity_repository) {
$this->entityRepository = $entity_repository;
}
/**
* {@inheritdoc}
*/
public function resolve(NormalizerInterface $normalizer, $data, $entity_type) {
// The normalizer is what knows the specification of the data being
// deserialized. If it can return a UUID from that data, and if there's an
// entity with that UUID, then return its ID.
if ($normalizer instanceof UuidReferenceInterface && ($uuid = $normalizer
->getUuid($data))) {
if ($entity = $this->entityRepository
->loadEntityByUuid($entity_type, $uuid)) {
return $entity
->id();
}
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UuidResolver:: |
protected | property | The entity repository. | |
UuidResolver:: |
public | function |
Returns the local ID of an entity referenced by serialized data. Overrides EntityResolverInterface:: |
|
UuidResolver:: |
public | function | Constructs a UuidResolver object. |