You are here

public function ContentEntityNormalizer::normalize in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/Normalizer/ContentEntityNormalizer.php \Drupal\content_sync\Normalizer\ContentEntityNormalizer::normalize()

Overrides ContentEntityNormalizer::normalize

2 calls to ContentEntityNormalizer::normalize()
FileEntityNormalizer::normalize in src/Normalizer/FileEntityNormalizer.php
Normalizes an object into a set of arrays/scalars.
UserEntityNormalizer::normalize in src/Normalizer/UserEntityNormalizer.php
Normalizes an object into a set of arrays/scalars.
2 methods override ContentEntityNormalizer::normalize()
FileEntityNormalizer::normalize in src/Normalizer/FileEntityNormalizer.php
Normalizes an object into a set of arrays/scalars.
UserEntityNormalizer::normalize in src/Normalizer/UserEntityNormalizer.php
Normalizes an object into a set of arrays/scalars.

File

src/Normalizer/ContentEntityNormalizer.php, line 118

Class

ContentEntityNormalizer
Adds the file URI to embedded file entities.

Namespace

Drupal\content_sync\Normalizer

Code

public function normalize($object, $format = NULL, array $context = []) {

  /* @var ContentEntityInterface $object */
  $normalized_data = parent::normalize($object, $format, $context);
  $normalized_data['_content_sync'] = $this
    ->getContentSyncMetadata($object, $context);

  /**
   * @var \Drupal\Core\Entity\ContentEntityBase $object
   */
  $referenced_entities = $object
    ->referencedEntities();

  // Add node uuid for menu link if any.
  if ($object
    ->getEntityTypeId() == 'menu_link_content') {
    if ($entity = $this
      ->getMenuLinkNodeAttached($object)) {
      $normalized_data['_content_sync']['menu_entity_link'][$entity
        ->getEntityTypeId()] = $entity
        ->uuid();
      $referenced_entities[] = $entity;
    }
  }
  if (!empty($referenced_entities)) {
    $dependencies = [];
    foreach ($referenced_entities as $entity) {
      $reflection = new \ReflectionClass($entity);
      if ($reflection
        ->implementsInterface(ContentEntityInterface::class)) {
        $ids = [
          $entity
            ->getEntityTypeId(),
          $entity
            ->bundle(),
          $entity
            ->uuid(),
        ];
        $dependency = implode(ContentSyncManager::DELIMITER, $ids);
        if (!$this
          ->inDependencies($dependency, $dependencies)) {
          $dependencies[$entity
            ->getEntityTypeId()][] = $dependency;
        }
      }
    }
    $normalized_data['_content_sync']['entity_dependencies'] = $dependencies;
  }

  // Decorate normalized entity before retuning it.
  if (is_a($object, ContentEntityInterface::class, TRUE)) {
    $this
      ->decorateNormalization($normalized_data, $object, $format, $context);
  }
  return $normalized_data;
}