class FieldItemNormalizer extends NormalizerBase implements DenormalizerInterface (View source)

internal  JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
 

Converts the Drupal field item object to a JSON:API array structure.

Traits

A trait providing methods for serialized columns.

SerializerAwareTrait

Properties

protected string $supportedInterfaceOrClass

The interface or class that this Normalizer supports.

protected $format {@inheritdoc} from  NormalizerBase
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

Methods

supportsNormalization($data, $format = NULL)

{@inheritdoc}

supportsDenormalization($data, $type, $format = NULL)

Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization()

bool
checkFormat(string $format = NULL)

Checks if the provided format is supported by this normalizer.

addCacheableDependency(array $context, $data)

Adds cacheability if applicable.

static mixed
rasterizeValueRecursive(mixed $value)

Rasterizes a value recursively.

checkForSerializedStrings(mixed $data, string $class, FieldItemInterface $field_item)

Checks if there is a serialized string for a column.

bool
dataHasStringForSerializeColumn(FieldItemInterface $field_item, array $data)

Checks if the data contains string value for serialize column.

string[]
getSerializedPropertyNames(FieldItemInterface $field_item)

Gets the names of all serialized properties.

string[]
getCustomSerializedPropertyNames(FieldItemInterface $field_item)

Gets the names of all properties the plugin treats as serialized data.

__construct(EntityTypeManagerInterface $entity_type_manager)

FieldItemNormalizer constructor.

normalize($field_item, $format = NULL, array $context = [])

{@inheritdoc}

denormalize($data, $class, $format = NULL, array $context = [])

{@inheritdoc}

getFieldItemInstance(ResourceType $resource_type, FieldItemDataDefinitionInterface $item_definition)

Gets a field item instance for use with SerializedColumnNormalizerTrait.

Details

supportsNormalization($data, $format = NULL)

{@inheritdoc}

Parameters

$data
$format

supportsDenormalization($data, $type, $format = NULL)

Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization()

This class doesn't implement DenormalizerInterface, but most of its child classes do. Therefore, this method is implemented at this level to reduce code duplication.

Parameters

$data
$type
$format

protected bool checkFormat(string $format = NULL)

Checks if the provided format is supported by this normalizer.

Parameters

string $format

The format to check.

Return Value

bool

TRUE if the format is supported, FALSE otherwise. If no format is specified this will return TRUE.

protected addCacheableDependency(array $context, $data)

Adds cacheability if applicable.

Parameters

array $context

Context options for the normalizer.

$data

The data that might have cacheability information.

static protected mixed rasterizeValueRecursive(mixed $value)

Rasterizes a value recursively.

This is mainly for configuration entities where a field can be a tree of values to rasterize.

Parameters

mixed $value

Either a scalar, an array or a rasterizable object.

Return Value

mixed

The rasterized value.

protected checkForSerializedStrings(mixed $data, string $class, FieldItemInterface $field_item)

Checks if there is a serialized string for a column.

Parameters

mixed $data

The field item data to denormalize.

string $class

The expected class to instantiate.

FieldItemInterface $field_item

The field item.

protected bool dataHasStringForSerializeColumn(FieldItemInterface $field_item, array $data)

Checks if the data contains string value for serialize column.

Parameters

FieldItemInterface $field_item

The field item.

array $data

The data being denormalized.

Return Value

bool

TRUE if there is a string value for serialize column, otherwise FALSE.

protected string[] getSerializedPropertyNames(FieldItemInterface $field_item)

Gets the names of all serialized properties.

Parameters

FieldItemInterface $field_item

The field item.

Return Value

string[]

The property names for serialized properties.

protected string[] getCustomSerializedPropertyNames(FieldItemInterface $field_item)

Gets the names of all properties the plugin treats as serialized data.

This allows the field storage definition or entity type to provide a setting for serialized properties. This can be used for fields that handle serialized data themselves and do not rely on the serialized schema flag.

Parameters

FieldItemInterface $field_item

The field item.

Return Value

string[]

The property names for serialized properties.

__construct(EntityTypeManagerInterface $entity_type_manager)

FieldItemNormalizer constructor.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

normalize($field_item, $format = NULL, array $context = [])

{@inheritdoc}

This normalizer leaves JSON:API normalizer land and enters the land of Drupal core's serialization system. That system was never designed with cacheability in mind, and hence bubbles cacheability out of band. This must catch it, and pass it to the value object that JSON:API uses.

Parameters

$field_item
$format
array $context

denormalize($data, $class, $format = NULL, array $context = [])

{@inheritdoc}

Parameters

$data
$class
$format
array $context

protected getFieldItemInstance(ResourceType $resource_type, FieldItemDataDefinitionInterface $item_definition)

Gets a field item instance for use with SerializedColumnNormalizerTrait.

Parameters

ResourceType $resource_type

The JSON:API resource type of the entity being denormalized.

FieldItemDataDefinitionInterface $item_definition

The field item definition of the instance to get.

Exceptions

InvalidPluginDefinitionException
PluginNotFoundException