You are here

class PathFieldItemListNormalizer in Replication 8

Normalizes path field.

Hierarchy

Expanded class hierarchy of PathFieldItemListNormalizer

1 string reference to 'PathFieldItemListNormalizer'
replication.services.yml in ./replication.services.yml
replication.services.yml
1 service uses PathFieldItemListNormalizer
replication.normalizer.path_field_item_list in ./replication.services.yml
Drupal\replication\Normalizer\PathFieldItemListNormalizer

File

src/Normalizer/PathFieldItemListNormalizer.php, line 10

Namespace

Drupal\replication\Normalizer
View source
class PathFieldItemListNormalizer extends FieldNormalizer {

  /**
   * {@inheritdoc}
   */
  protected $supportedInterfaceOrClass = [
    'Drupal\\path\\Plugin\\Field\\FieldType\\PathFieldItemList',
    'Drupal\\multiversion\\MultiversionFieldItemList',
  ];

  /**
   * @var string[]
   */
  protected $format = [
    'json',
  ];

  /**
   * {@inheritdoc}
   */
  public function normalize($field_item, $format = NULL, array $context = []) {
    $value = $field_item
      ->getValue();
    $entity = $field_item
      ->getEntity();
    if (isset($entity->path->pathauto)) {
      $value[0]['pathauto'] = $entity->path->pathauto;
    }
    return $value;
  }

  /**
   * {@inheritdoc}
   */
  public function denormalize($data, $class, $format = NULL, array $context = []) {
    if (isset($data[0]['pid'])) {
      unset($data[0]['pid']);
    }
    if (isset($data[0]['source'])) {
      unset($data[0]['source']);
    }
    if (isset($data[0]['workspace'])) {
      unset($data[0]['workspace']);
    }
    return parent::denormalize($data, $class, $format, $context);
  }

  /**
   * {@inheritdoc}
   */
  public function supportsDenormalization($data, $type, $format = NULL) {
    if (in_array($type, [
      'Drupal\\path\\Plugin\\Field\\FieldType\\PathFieldItemList',
      'Drupal\\multiversion\\MultiversionFieldItemList',
    ])) {
      return TRUE;
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 2
NormalizerBase::supportsNormalization public function Checks whether the given class is supported for normalization by this normalizer. 1
PathFieldItemListNormalizer::$format protected property Overrides NormalizerBase::$format
PathFieldItemListNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides FieldNormalizer::$supportedInterfaceOrClass
PathFieldItemListNormalizer::denormalize public function Denormalizes data back into an object of the given class. Overrides FieldNormalizer::denormalize
PathFieldItemListNormalizer::normalize public function Normalizes an object into a set of arrays/scalars. Overrides ListNormalizer::normalize
PathFieldItemListNormalizer::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() Overrides NormalizerBase::supportsDenormalization