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