class UserDataCdfAttribute in Acquia Content Hub 8.2
Extracts user specific data for identifying duplicate and anonymous users.
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\UserDataCdfAttribute implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of UserDataCdfAttribute
1 file declares its use of UserDataCdfAttribute
- UserDataCdfAttributeTest.php in tests/
src/ Unit/ EventSubscriber/ CdfAttributes/ UserDataCdfAttributeTest.php
1 string reference to 'UserDataCdfAttribute'
1 service uses UserDataCdfAttribute
File
- src/
EventSubscriber/ CdfAttributes/ UserDataCdfAttribute.php, line 13
Namespace
Drupal\acquia_contenthub\EventSubscriber\CdfAttributesView source
class UserDataCdfAttribute implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::POPULATE_CDF_ATTRIBUTES][] = [
'onPopulateAttributes',
100,
];
return $events;
}
/**
* Method called on the POPULATE_CDF_ATTRIBUTES event.
*
* Extracts user specific data for identifying duplicate and anonymous users.
*
* @param \Drupal\acquia_contenthub\Event\CdfAttributesEvent $event
* The CdfAttributesEvent object.
*
* @throws \Exception
*/
public function onPopulateAttributes(CdfAttributesEvent $event) {
$entity = $event
->getEntity();
if ($entity
->getEntityTypeId() !== 'user') {
return;
}
/** @var \Drupal\user\Entity\User $entity */
$cdf = $event
->getCdf();
$cdf
->addAttribute('username', CDFAttribute::TYPE_STRING, $entity
->label());
if ($entity
->isAnonymous()) {
$cdf
->addAttribute('is_anonymous', CDFAttribute::TYPE_BOOLEAN, TRUE);
}
elseif ($entity
->getEmail()) {
$cdf
->addAttribute('mail', CDFAttribute::TYPE_STRING, $entity
->getEmail());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UserDataCdfAttribute:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
UserDataCdfAttribute:: |
public | function | Method called on the POPULATE_CDF_ATTRIBUTES event. |