You are here

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'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses LoadEntityByUuid
acquia_contenthub.load_local_entity.by_uuid in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\LoadLocalEntity\LoadEntityByUuid

File

src/EventSubscriber/LoadLocalEntity/LoadEntityByUuid.php, line 17

Namespace

Drupal\acquia_contenthub\EventSubscriber\LoadLocalEntity
View 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

Namesort descending Modifiers Type Description Overrides
LoadEntityByUuid::getEntityRepository protected function Gets the entity repository.
LoadEntityByUuid::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
LoadEntityByUuid::onLoadLocalEntity public function Reacts to local entity load events.