class FieldNormalizer
Same name in this branch
- 8.9.x core/modules/jsonapi/src/Normalizer/FieldNormalizer.php \Drupal\jsonapi\Normalizer\FieldNormalizer
- 8.9.x core/modules/hal/src/Normalizer/FieldNormalizer.php \Drupal\hal\Normalizer\FieldNormalizer
Same name in other branches
- 9 core/modules/jsonapi/src/Normalizer/FieldNormalizer.php \Drupal\jsonapi\Normalizer\FieldNormalizer
- 9 core/modules/serialization/src/Normalizer/FieldNormalizer.php \Drupal\serialization\Normalizer\FieldNormalizer
- 9 core/modules/hal/src/Normalizer/FieldNormalizer.php \Drupal\hal\Normalizer\FieldNormalizer
- 10 core/modules/jsonapi/src/Normalizer/FieldNormalizer.php \Drupal\jsonapi\Normalizer\FieldNormalizer
- 10 core/modules/serialization/src/Normalizer/FieldNormalizer.php \Drupal\serialization\Normalizer\FieldNormalizer
- 11.x core/modules/jsonapi/src/Normalizer/FieldNormalizer.php \Drupal\jsonapi\Normalizer\FieldNormalizer
- 11.x core/modules/serialization/src/Normalizer/FieldNormalizer.php \Drupal\serialization\Normalizer\FieldNormalizer
Denormalizes data to Drupal field values.
This class simply calls denormalize() on the individual FieldItems. The FieldItem normalizers are responsible for setting the field values for each item.
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
- class \Drupal\serialization\Normalizer\FieldNormalizer extends \Drupal\serialization\Normalizer\ListNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\serialization\Normalizer\ListNormalizer extends \Drupal\serialization\Normalizer\NormalizerBase
Expanded class hierarchy of FieldNormalizer
See also
\Drupal\serialization\Normalizer\FieldItemNormalizer.
1 file declares its use of FieldNormalizer
- FieldNormalizer.php in core/
modules/ hal/ src/ Normalizer/ FieldNormalizer.php
1 string reference to 'FieldNormalizer'
- serialization.services.yml in core/
modules/ serialization/ serialization.services.yml - core/modules/serialization/serialization.services.yml
1 service uses FieldNormalizer
- serialization.normalizer.field in core/
modules/ serialization/ serialization.services.yml - Drupal\serialization\Normalizer\FieldNormalizer
File
-
core/
modules/ serialization/ src/ Normalizer/ FieldNormalizer.php, line 19
Namespace
Drupal\serialization\NormalizerView source
class FieldNormalizer extends ListNormalizer implements DenormalizerInterface {
/**
* {@inheritdoc}
*/
protected $supportedInterfaceOrClass = FieldItemListInterface::class;
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
if (!isset($context['target_instance'])) {
throw new InvalidArgumentException('$context[\'target_instance\'] must be set to denormalize with the FieldNormalizer');
}
if ($context['target_instance']->getParent() == NULL) {
throw new InvalidArgumentException('The field passed in via $context[\'target_instance\'] must have a parent set.');
}
/** @var \Drupal\Core\Field\FieldItemListInterface $items */
$items = $context['target_instance'];
$item_class = $items->getItemDefinition()
->getClass();
if (!is_array($data)) {
throw new UnexpectedValueException(sprintf('Field values for "%s" must use an array structure', $items->getName()));
}
foreach ($data as $item_data) {
// Create a new item and pass it as the target for the unserialization of
// $item_data. All items in field should have removed before this method
// was called.
// @see \Drupal\serialization\Normalizer\ContentEntityNormalizer::denormalize().
$context['target_instance'] = $items->appendItem();
$this->serializer
->denormalize($item_data, $item_class, $format, $context);
}
return $items;
}
}
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. | |||
FieldNormalizer::$supportedInterfaceOrClass | protected | property | The interface or class that this Normalizer supports. | Overrides ListNormalizer::$supportedInterfaceOrClass | |
FieldNormalizer::denormalize | public | function | |||
ListNormalizer::normalize | public | function | 1 | ||
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. | 2 | |
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.