function UuidResolver::resolve
Same name in other branches
- 8.9.x core/modules/serialization/src/EntityResolver/UuidResolver.php \Drupal\serialization\EntityResolver\UuidResolver::resolve()
- 10 core/modules/serialization/src/EntityResolver/UuidResolver.php \Drupal\serialization\EntityResolver\UuidResolver::resolve()
- 11.x core/modules/serialization/src/EntityResolver/UuidResolver.php \Drupal\serialization\EntityResolver\UuidResolver::resolve()
Overrides EntityResolverInterface::resolve
File
-
core/
modules/ serialization/ src/ EntityResolver/ UuidResolver.php, line 33
Class
- UuidResolver
- Resolves entities from data that contains an entity UUID.
Namespace
Drupal\serialization\EntityResolverCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.