You are here

public function AnonymousUser::onDataTamper in Acquia Content Hub 8.2

Tamper with CDF data before its imported.

Parameters

\Drupal\acquia_contenthub\Event\EntityDataTamperEvent $event: The data tamper event.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

File

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

Class

AnonymousUser
Replace anonymous user with the local anonymous user.

Namespace

Drupal\acquia_contenthub\EventSubscriber\EntityDataTamper

Code

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);
      }
    }
  }
}