You are here

class ExistingEntity in Acquia Content Hub 8.2

Place existing entities into the dependency stack.

Hierarchy

  • class \Drupal\acquia_contenthub_subscriber\EventSubscriber\EntityDataTamper\ExistingEntity implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ExistingEntity

1 string reference to 'ExistingEntity'
acquia_contenthub_subscriber.services.yml in modules/acquia_contenthub_subscriber/acquia_contenthub_subscriber.services.yml
modules/acquia_contenthub_subscriber/acquia_contenthub_subscriber.services.yml
1 service uses ExistingEntity
acquia_contenthub_subscriber.data_tamper.existing_entity in modules/acquia_contenthub_subscriber/acquia_contenthub_subscriber.services.yml
Drupal\acquia_contenthub_subscriber\EventSubscriber\EntityDataTamper\ExistingEntity

File

modules/acquia_contenthub_subscriber/src/EventSubscriber/EntityDataTamper/ExistingEntity.php, line 14

Namespace

Drupal\acquia_contenthub_subscriber\EventSubscriber\EntityDataTamper
View source
class ExistingEntity implements EventSubscriberInterface {

  /**
   * The subscriber tracker.
   *
   * @var \Drupal\acquia_contenthub_subscriber\SubscriberTracker
   */
  protected $tracker;

  /**
   * ExistingEntity constructor.
   *
   * @param \Drupal\acquia_contenthub_subscriber\SubscriberTracker $tracker
   *   Subscriber tracker.
   */
  public function __construct(SubscriberTracker $tracker) {
    $this->tracker = $tracker;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[AcquiaContentHubEvents::ENTITY_DATA_TAMPER][] = [
      'onDataTamper',
      100,
    ];
    return $events;
  }

  /**
   * Tamper with CDF data before its imported.
   *
   * @param \Drupal\acquia_contenthub\Event\EntityDataTamperEvent $event
   *   The data tamper event.
   *
   * @throws \Exception
   */
  public function onDataTamper(EntityDataTamperEvent $event) {
    $cdf = $event
      ->getCdf();
    foreach ($cdf
      ->getEntities() as $uuid => $object) {

      // @todo we want to compare by hashes eventually.
      $hash = $object
        ->getAttribute('hash')
        ->getValue()['und'];
      $entity = $this->tracker
        ->getEntityByRemoteIdAndHash($uuid, $hash);
      if ($entity) {
        $wrapper = new DependentEntityWrapper($entity);
        $wrapper
          ->setRemoteUuid($uuid);
        $event
          ->getStack()
          ->addDependency($wrapper);
        $this->tracker
          ->setStatusByUuid($uuid, SubscriberTracker::IMPORTED);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExistingEntity::$tracker protected property The subscriber tracker.
ExistingEntity::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ExistingEntity::onDataTamper public function Tamper with CDF data before its imported.
ExistingEntity::__construct public function ExistingEntity constructor.