You are here

class PasswordFieldSerializer in Acquia Content Hub 8.2

Password Field Serializer.

@package Drupal\acquia_contenthub\EventSubscriber\SerializeContentField

Hierarchy

  • class \Drupal\acquia_contenthub\EventSubscriber\SerializeContentField\FallbackFieldSerializer implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses ContentFieldMetadataTrait
    • class \Drupal\acquia_contenthub\EventSubscriber\SerializeContentField\PasswordFieldSerializer implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of PasswordFieldSerializer

1 string reference to 'PasswordFieldSerializer'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses PasswordFieldSerializer
password.field.cdf.serializer in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\SerializeContentField\PasswordFieldSerializer

File

src/EventSubscriber/SerializeContentField/PasswordFieldSerializer.php, line 14

Namespace

Drupal\acquia_contenthub\EventSubscriber\SerializeContentField
View source
class PasswordFieldSerializer extends FallbackFieldSerializer implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[AcquiaContentHubEvents::SERIALIZE_CONTENT_ENTITY_FIELD][] = [
      'onSerializeContentField',
      5,
    ];
    return $events;
  }

  /**
   * Manipulate the password properties.
   *
   * @param \Drupal\acquia_contenthub\Event\SerializeCdfEntityFieldEvent $event
   *   The content entity field serialization event.
   */
  public function onSerializeContentField(SerializeCdfEntityFieldEvent $event) {
    if ($event
      ->getField()
      ->getFieldDefinition()
      ->getType() == 'password') {
      parent::onSerializeContentField($event);
      if ($values = $event
        ->getFieldData()) {
        foreach ($values['value'] as $langcode => $value) {
          $values['value'][$langcode]['pre_hashed'] = TRUE;
        }
        $event
          ->setFieldData($values);
        $event
          ->stopPropagation();
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentFieldMetadataTrait::setFieldMetaData protected function Sets field metadata.
PasswordFieldSerializer::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides FallbackFieldSerializer::getSubscribedEvents
PasswordFieldSerializer::onSerializeContentField public function Manipulate the password properties. Overrides FallbackFieldSerializer::onSerializeContentField