Mercurial > hg > isophonics-drupal-site
view core/modules/serialization/src/EntityResolver/UuidResolver.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
line wrap: on
line source
<?php namespace Drupal\serialization\EntityResolver; use Drupal\Core\Entity\EntityManagerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** * Resolves entities from data that contains an entity UUID. */ class UuidResolver implements EntityResolverInterface { /** * The entity manager. * * @var \Drupal\Core\Entity\EntityManagerInterface */ protected $entityManager; /** * Constructs a UuidResolver object. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. */ public function __construct(EntityManagerInterface $entity_manager) { $this->entityManager = $entity_manager; } /** * {@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->entityManager->loadEntityByUuid($entity_type, $uuid)) { return $entity->id(); } } return NULL; } }