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'
1 service uses AnonymousUser
File
- src/
EventSubscriber/ EntityDataTamper/ AnonymousUser.php, line 13
Namespace
Drupal\acquia_contenthub\EventSubscriber\EntityDataTamperView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AnonymousUser:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
AnonymousUser:: |
public | function | Tamper with CDF data before its imported. |