class ListNormalizer
Same name in other branches
- 9 core/modules/serialization/src/Normalizer/ListNormalizer.php \Drupal\serialization\Normalizer\ListNormalizer
- 8.9.x core/modules/serialization/src/Normalizer/ListNormalizer.php \Drupal\serialization\Normalizer\ListNormalizer
- 11.x core/modules/serialization/src/Normalizer/ListNormalizer.php \Drupal\serialization\Normalizer\ListNormalizer
Converts list objects to arrays.
Ordinarily, this would be handled automatically by Serializer, but since there is a TypedDataNormalizer and the Field class extends TypedData, any Field will be handled by that Normalizer instead of being traversed. This class ensures that TypedData classes that also implement ListInterface are traversed instead of simply returning getValue().
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, \Drupal\serialization\Normalizer\CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\serialization\Normalizer\ListNormalizer extends \Drupal\serialization\Normalizer\NormalizerBase
Expanded class hierarchy of ListNormalizer
1 file declares its use of ListNormalizer
- ListNormalizerTest.php in core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ ListNormalizerTest.php
1 string reference to 'ListNormalizer'
- serialization.services.yml in core/
modules/ serialization/ serialization.services.yml - core/modules/serialization/serialization.services.yml
1 service uses ListNormalizer
- serializer.normalizer.list in core/
modules/ serialization/ serialization.services.yml - Drupal\serialization\Normalizer\ListNormalizer
File
-
core/
modules/ serialization/ src/ Normalizer/ ListNormalizer.php, line 16
Namespace
Drupal\serialization\NormalizerView source
class ListNormalizer extends NormalizerBase {
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = []) : array|string|int|float|bool|\ArrayObject|null {
$attributes = [];
foreach ($object as $fieldItem) {
$attributes[] = $this->serializer
->normalize($fieldItem, $format, $context);
}
return $attributes;
}
/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format) : array {
return [
ListInterface::class => TRUE,
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY | constant | Name of key for bubbling cacheability metadata via serialization context. | |||
ListNormalizer::getSupportedTypes | public | function | Overrides NormalizerBase::getSupportedTypes | 1 | |
ListNormalizer::normalize | public | function | |||
NormalizerBase::$format | protected | property | List of formats which supports (de-)normalization. | 1 | |
NormalizerBase::addCacheableDependency | protected | function | Adds cacheability if applicable. | ||
NormalizerBase::checkFormat | protected | function | Checks if the provided format is supported by this normalizer. | 1 | |
NormalizerBase::hasCacheableSupportsMethod | public | function | 16 | ||
NormalizerBase::supportsDenormalization | public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 | |
NormalizerBase::supportsNormalization | public | function | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.