You are here

class AnonymousUser in Acquia Content Hub 8.2

Replace anonymous user with the local anonymous user.

Hierarchy

  • class \Drupal\acquia_contenthub\EventSubscriber\EntityDataTamper\AnonymousUser implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of AnonymousUser

1 file declares its use of AnonymousUser
AnonymousUserTest.php in tests/src/Kernel/EventSubscriber/EntityDataTamper/AnonymousUserTest.php
1 string reference to 'AnonymousUser'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses AnonymousUser
anonymous_user.data.tamper in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\EntityDataTamper\AnonymousUser

File

src/EventSubscriber/EntityDataTamper/AnonymousUser.php, line 13

Namespace

Drupal\acquia_contenthub\EventSubscriber\EntityDataTamper
View source
class AnonymousUser implements EventSubscriberInterface {

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

  /**
   * Tamper with CDF data before its imported.
   *
   * @param \Drupal\acquia_contenthub\Event\EntityDataTamperEvent $event
   *   The data tamper event.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  public function onDataTamper(EntityDataTamperEvent $event) {
    foreach ($event
      ->getCdf()
      ->getEntities() as $uuid => $object) {
      $entity_type = $object
        ->getAttribute('entity_type');
      if ($entity_type && $entity_type
        ->getValue()['und'] == 'user') {
        $anonymous = $object
          ->getAttribute('is_anonymous');

        // The attribute won't be present if the user is not anonymous.
        if ($anonymous) {
          $entity = \Drupal::entityTypeManager()
            ->getStorage('user')
            ->load(0);
          $wrapper = new DependentEntityWrapper($entity);
          $wrapper
            ->setRemoteUuid($uuid);
          $event
            ->getStack()
            ->addDependency($wrapper);
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AnonymousUser::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
AnonymousUser::onDataTamper public function Tamper with CDF data before its imported.