class PathFieldItemListNormalizer in Replication 8
Normalizes path field.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\serialization\Normalizer\ListNormalizer
- class \Drupal\serialization\Normalizer\FieldNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\replication\Normalizer\PathFieldItemListNormalizer
- class \Drupal\serialization\Normalizer\FieldNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\serialization\Normalizer\ListNormalizer
Expanded class hierarchy of PathFieldItemListNormalizer
1 string reference to 'PathFieldItemListNormalizer'
1 service uses PathFieldItemListNormalizer
File
- src/
Normalizer/ PathFieldItemListNormalizer.php, line 10
Namespace
Drupal\replication\NormalizerView 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;
}
}