class LoadEntityByUuid in Acquia Content Hub 8.2
Loads local entities by UUID.
Loads a Local Entity by UUID.
@package Drupal\acquia_contenthub\EventSubscriber\LoadLocalEntity
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\LoadLocalEntity\LoadEntityByUuid implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of LoadEntityByUuid
1 string reference to 'LoadEntityByUuid'
1 service uses LoadEntityByUuid
File
- src/
EventSubscriber/ LoadLocalEntity/ LoadEntityByUuid.php, line 17
Namespace
Drupal\acquia_contenthub\EventSubscriber\LoadLocalEntityView source
class LoadEntityByUuid implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::LOAD_LOCAL_ENTITY][] = [
'onLoadLocalEntity',
10,
];
return $events;
}
/**
* Reacts to local entity load events.
*
* @param \Drupal\acquia_contenthub\Event\LoadLocalEntityEvent $event
* The local entity loading event.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* @throws \Exception
*/
public function onLoadLocalEntity(LoadLocalEntityEvent $event) {
$cdf = $event
->getCdf();
$entity_type_id = $cdf
->getAttribute('entity_type')
->getValue()[CDFObject::LANGUAGE_UNDETERMINED];
if ($entity = $this
->getEntityRepository()
->loadEntityByUuid($entity_type_id, $cdf
->getUuid())) {
$event
->setEntity($entity);
$event
->stopPropagation();
}
}
/**
* Gets the entity repository.
*
* @return \Drupal\Core\Entity\EntityRepositoryInterface
* The Entity Repository Service.
*/
protected function getEntityRepository() {
return \Drupal::service('entity.repository');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LoadEntityByUuid:: |
protected | function | Gets the entity repository. | |
LoadEntityByUuid:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
LoadEntityByUuid:: |
public | function | Reacts to local entity load events. |