You are here

class UserEntityNormalizer in Content Synchronization 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Normalizer/UserEntityNormalizer.php \Drupal\content_sync\Normalizer\UserEntityNormalizer

User entity normalizer class.

Hierarchy

Expanded class hierarchy of UserEntityNormalizer

1 string reference to 'UserEntityNormalizer'
content_sync.services.yml in ./content_sync.services.yml
content_sync.services.yml
1 service uses UserEntityNormalizer
content_sync.normalizer.user_entity in ./content_sync.services.yml
Drupal\content_sync\Normalizer\UserEntityNormalizer

File

src/Normalizer/UserEntityNormalizer.php, line 8

Namespace

Drupal\content_sync\Normalizer
View source
class UserEntityNormalizer extends ContentEntityNormalizer {

  /**
   * The interface or class that this Normalizer supports.
   *
   * @var string
   */
  protected $supportedInterfaceOrClass = 'Drupal\\user\\UserInterface';

  /**
   * {@inheritdoc}
   */
  public function denormalize($data, $class, $format = NULL, array $context = []) {
    $entity = parent::denormalize($data, $class, $format, $context);

    // For security reasons the user 1 is not updated.
    if ((int) $entity
      ->id() === 1) {
      return $entity
        ->load(1);
    }

    // User 0 is not updated.
    if (!empty($data['_content_sync']['is_anonymous']) && (int) $entity
      ->id() === 0) {
      return $entity
        ->load(0);
    }
    return $entity;
  }

  /**
   * {@inheritdoc}
   */
  public function normalize($object, $format = NULL, array $context = []) {
    $normalized_data = parent::normalize($object, $format, $context);
    if (!empty($context['content_sync'])) {
      $normalized_data['pass'] = [
        [
          'value' => $object
            ->getPassword(),
          'pre_hashed' => TRUE,
        ],
      ];
      $normalized_data['mail'] = [
        'value' => $object
          ->getEmail(),
      ];
      $normalized_data['status'] = [
        'value' => $object
          ->get('status')->value,
      ];
      $normalized_data['roles'] = $object
        ->getRoles();
    }
    return $normalized_data;
  }

  /**
   * {@inheritdoc}
   */
  protected function getContentSyncMetadata($object, $context = []) {

    /** @var \Drupal\user\Entity\User $object */
    $metadata = parent::getContentSyncMetadata($object, $context);
    if ($object
      ->isAnonymous()) {
      $metadata['is_anonymous'] = TRUE;
    }
    return $metadata;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
ContentEntityNormalizer::$decoratorManager protected property
ContentEntityNormalizer::$entityRepository protected property The entity repository.
ContentEntityNormalizer::$entityTypeBundleInfo protected property The entity bundle info.
ContentEntityNormalizer::cleanupData protected function
ContentEntityNormalizer::fixReferences protected function
ContentEntityNormalizer::getDecoratorManager protected function @inheritdoc Overrides SyncNormalizerDecoratorTrait::getDecoratorManager
ContentEntityNormalizer::getMenuLinkNodeAttached protected function Gets a node attached to a menu link. The node has already been imported.
ContentEntityNormalizer::getPathLinkNodeAttached protected function Gets a node attached to a path alias. The node has already been imported.
ContentEntityNormalizer::inDependencies protected function Checks if a dependency is in a dependencies nested array.
ContentEntityNormalizer::supportsDenormalization public function @inheritdoc Overrides NormalizerBase::supportsDenormalization
ContentEntityNormalizer::supportsNormalization public function @inheritdoc Overrides NormalizerBase::supportsNormalization
ContentEntityNormalizer::__construct public function Constructs an EntityNormalizer object. Overrides EntityNormalizer::__construct 1
FieldableEntityNormalizerTrait::$entityFieldManager protected property The entity field manager.
FieldableEntityNormalizerTrait::$entityTypeManager protected property The entity type manager. 1
FieldableEntityNormalizerTrait::$entityTypeRepository protected property The entity type repository.
FieldableEntityNormalizerTrait::constructValue protected function Build the field item value using the incoming data. 7
FieldableEntityNormalizerTrait::denormalizeFieldData protected function Denormalizes entity data by denormalizing each field individually.
FieldableEntityNormalizerTrait::determineEntityTypeId protected function Determines the entity type ID to denormalize as.
FieldableEntityNormalizerTrait::extractBundleData protected function Denormalizes the bundle property so entity creation can use it.
FieldableEntityNormalizerTrait::getEntityFieldManager protected function Returns the entity field manager.
FieldableEntityNormalizerTrait::getEntityTypeDefinition protected function Gets the entity type definition.
FieldableEntityNormalizerTrait::getEntityTypeManager protected function Returns the entity type manager.
FieldableEntityNormalizerTrait::getEntityTypeRepository protected function Returns the entity type repository.
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 1
SyncNormalizerDecoratorTrait::decorateDenormalization protected function
SyncNormalizerDecoratorTrait::decorateDenormalizedEntity protected function
SyncNormalizerDecoratorTrait::decorateNormalization protected function
UserEntityNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides ContentEntityNormalizer::$supportedInterfaceOrClass
UserEntityNormalizer::denormalize public function Overrides ContentEntityNormalizer::denormalize
UserEntityNormalizer::getContentSyncMetadata protected function Overrides ContentEntityNormalizer::getContentSyncMetadata
UserEntityNormalizer::normalize public function Overrides ContentEntityNormalizer::normalize