class EntityReferenceFieldItemNormalizer extends FieldItemNormalizer (View source)

Adds the file URI to embedded file entities.

Traits

Converts empty reference values for entity reference items.

A trait for providing fieldable entity normalization/denormalization methods.

A trait providing methods for serialized columns.

SerializerAwareTrait

Properties

protected $supportedInterfaceOrClass {@inheritdoc}
protected string|string[] $format

List of formats which supports (de-)normalization.

from  NormalizerBase
protected EntityFieldManagerInterface $entityFieldManager

The entity field manager.

from  FieldableEntityNormalizerTrait
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

from  FieldableEntityNormalizerTrait
protected EntityTypeRepositoryInterface $entityTypeRepository

The entity type repository.

from  FieldableEntityNormalizerTrait
protected EntityRepositoryInterface $entityRepository

The entity repository.

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.

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

{@inheritdoc}

string
determineEntityTypeId(string $class, array $context)

Determines the entity type ID to denormalize as.

getEntityTypeDefinition(string $entity_type_id)

Gets the entity type definition.

string
extractBundleData(array $data, EntityTypeInterface $entity_type_definition)

Denormalizes the bundle property so entity creation can use it.

denormalizeFieldData(array $data, FieldableEntityInterface $entity, string $format, array $context)

Denormalizes entity data by denormalizing each field individually.

mixed
constructValue(mixed $data, array $context)

Build the field item value using the incoming data.

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.

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

{@inheritdoc}

bool
fieldItemReferencesTaxonomyTerm(EntityReferenceItem $field_item)

Determines if a field item references a taxonomy term.

__construct(EntityRepositoryInterface $entity_repository)

Constructs an EntityReferenceFieldItemNormalizer object.

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.

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

{@inheritdoc}

Parameters

$field_item
$format
array $context

protected string determineEntityTypeId(string $class, array $context)

Determines the entity type ID to denormalize as.

Parameters

string $class

The entity type class to be denormalized to.

array $context

The serialization context data.

Return Value

string

The entity type ID.

protected EntityTypeInterface getEntityTypeDefinition(string $entity_type_id)

Gets the entity type definition.

Parameters

string $entity_type_id

The entity type ID to load the definition for.

Return Value

EntityTypeInterface

The loaded entity type definition.

Exceptions

UnexpectedValueException

protected string extractBundleData(array $data, EntityTypeInterface $entity_type_definition)

Denormalizes the bundle property so entity creation can use it.

Parameters

array $data

The data being denormalized.

EntityTypeInterface $entity_type_definition

The entity type definition.

Return Value

string

The valid bundle name.

Exceptions

UnexpectedValueException

protected denormalizeFieldData(array $data, FieldableEntityInterface $entity, string $format, array $context)

Denormalizes entity data by denormalizing each field individually.

Parameters

array $data

The data to denormalize.

FieldableEntityInterface $entity

The fieldable entity to set field values for.

string $format

The serialization format.

array $context

The context data.

protected EntityTypeRepositoryInterface getEntityTypeRepository()

Returns the entity type repository.

Return Value

EntityTypeRepositoryInterface

The entity type repository.

protected EntityFieldManagerInterface getEntityFieldManager()

Returns the entity field manager.

Return Value

EntityFieldManagerInterface

The entity field manager.

protected EntityTypeManagerInterface getEntityTypeManager()

Returns the entity type manager.

Return Value

EntityTypeManagerInterface

The entity type manager.

protected mixed constructValue(mixed $data, array $context)

Build the field item value using the incoming data.

Most normalizers that extend this class can simply use this method to construct the denormalized value without having to override denormalize() and reimplementing its validation logic or its call to set the field value.

It's recommended to not override this and instead provide a (de)normalizer at the DataType level.

Parameters

mixed $data

The incoming data for this field item.

array $context

The context passed into the Normalizer.

Return Value

mixed

The value to use in Entity::setValue().

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.

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

{@inheritdoc}

Parameters

$data
$class
$format
array $context

protected normalizeRootReferenceValue($values, EntityReferenceItem $field_item)

No description

Parameters

$values
EntityReferenceItem $field_item

protected bool fieldItemReferencesTaxonomyTerm(EntityReferenceItem $field_item)

Determines if a field item references a taxonomy term.

Parameters

EntityReferenceItem $field_item

The entity reference item.

Return Value

bool

__construct(EntityRepositoryInterface $entity_repository)

Constructs an EntityReferenceFieldItemNormalizer object.

Parameters

EntityRepositoryInterface $entity_repository

The entity repository.