class FieldTranslationSynchronizer implements FieldTranslationSynchronizerInterface (View source)

Provides field translation synchronization capabilities.

Properties

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected FieldTypePluginManagerInterface $fieldTypeManager

The field type plugin manager.

Methods

__construct(EntityTypeManagerInterface $entity_type_manager, FieldTypePluginManagerInterface $field_type_manager)

Constructs a FieldTranslationSynchronizer object.

string[]
getFieldSynchronizedProperties(FieldDefinitionInterface $field_definition)

Returns the synchronized properties for the specified field definition.

string[]
getFieldSynchronizationSettings(FieldDefinitionInterface $field_definition)

Returns the synchronization settings for the specified field.

synchronizeFields(ContentEntityInterface $entity, string $sync_langcode, string $original_langcode = NULL)

Performs field column synchronization on the given entity.

getOriginalEntity(ContentEntityInterface $entity)

Returns the original unchanged entity to be used to detect changes.

synchronizeItems(array $values, array $unchanged_items, string $sync_langcode, array $translations, array $properties)

Synchronize the items of a single field.

array
createMergedItem(array $source_item, array $target_item, array $properties)

Creates a merged item.

itemHash(array $items, int $delta, array $properties)

Computes a hash code for the specified item.

Details

__construct(EntityTypeManagerInterface $entity_type_manager, FieldTypePluginManagerInterface $field_type_manager)

Constructs a FieldTranslationSynchronizer object.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

FieldTypePluginManagerInterface $field_type_manager

The field type plugin manager.

string[] getFieldSynchronizedProperties(FieldDefinitionInterface $field_definition)

Returns the synchronized properties for the specified field definition.

Parameters

FieldDefinitionInterface $field_definition

A field definition.

Return Value

string[]

An array of synchronized field property names.

protected string[] getFieldSynchronizationSettings(FieldDefinitionInterface $field_definition)

Returns the synchronization settings for the specified field.

Parameters

FieldDefinitionInterface $field_definition

A field definition.

Return Value

string[]

An array of synchronized field property names.

synchronizeFields(ContentEntityInterface $entity, string $sync_langcode, string $original_langcode = NULL)

Performs field column synchronization on the given entity.

Field column synchronization takes care of propagating any change in the field items order and in the column values themselves to all the available translations. This functionality is provided by defining a 'translation_sync' key for the 'content_translation' module's portion of the field definition's 'third_party_settings', holding an array of column names to be synchronized. The synchronized column values are shared across translations, while the rest varies per-language. This is useful for instance to translate the "alt" and "title" textual elements of an image field, while keeping the same image on every translation.

Parameters

ContentEntityInterface $entity

The entity whose values should be synchronized.

string $sync_langcode

The language of the translation whose values should be used as source for synchronization.

string $original_langcode

(optional) If a new translation is being created, this should be the language code of the original values. Defaults to NULL.

protected ContentEntityInterface getOriginalEntity(ContentEntityInterface $entity)

Returns the original unchanged entity to be used to detect changes.

Parameters

ContentEntityInterface $entity

The entity being changed.

Return Value

ContentEntityInterface

The unchanged entity.

synchronizeItems(array $values, array $unchanged_items, string $sync_langcode, array $translations, array $properties)

Synchronize the items of a single field.

All the column values of the "active" language are compared to the unchanged values to detect any addition, removal or change in the items order. Subsequently the detected changes are performed on the field items in other available languages.

Parameters

array $values
array $unchanged_items

The unchanged items to be used to detect changes.

string $sync_langcode

The language code of the items to use as source values.

array $translations

An array of all the available language codes for the given field.

array $properties

An array of property names to be synchronized.

protected array createMergedItem(array $source_item, array $target_item, array $properties)

Creates a merged item.

Parameters

array $source_item

An item containing the untranslatable properties to be synchronized.

array $target_item

An item containing the translatable properties to be kept.

array $properties

An array of properties to be synchronized.

Return Value

array

A merged item array.

protected itemHash(array $items, int $delta, array $properties)

Computes a hash code for the specified item.

Parameters

array $items

An array of field items.

int $delta

The delta identifying the item to be processed.

array $properties

An array of column names to be synchronized.