You are here

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'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses UserDataCdfAttribute
entity.user_data.cdf.attribute in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\UserDataCdfAttribute

File

src/EventSubscriber/CdfAttributes/UserDataCdfAttribute.php, line 13

Namespace

Drupal\acquia_contenthub\EventSubscriber\CdfAttributes
View 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

Namesort descending Modifiers Type Description Overrides
UserDataCdfAttribute::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
UserDataCdfAttribute::onPopulateAttributes public function Method called on the POPULATE_CDF_ATTRIBUTES event.