class ContentTranslationSynchronizedFieldsConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface (View source)

internal  
 

Checks that synchronized fields are handled correctly in pending revisions.

As for untranslatable fields, two modes are supported:

  • When changes to untranslatable fields are configured to affect all revision translations, synchronized field properties can be changed only in default revisions.
  • When changes to untranslatable fields affect are configured to affect only the revision's default translation, synchronized field properties can be changed only when editing the default translation. This may lead to temporarily desynchronized values, when saving a pending revision for the default translation that changes a synchronized property. These are actually synchronized when saving changes to the default translation as a new default revision.

Properties

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected ContentTranslationManagerInterface $contentTranslationManager

The content translation manager.

protected FieldTranslationSynchronizerInterface $synchronizer

The field translation synchronizer.

Methods

__construct(EntityTypeManagerInterface $entity_type_manager, ContentTranslationManagerInterface $content_translation_manager, FieldTranslationSynchronizerInterface $synchronizer)

ContentTranslationSynchronizedFieldsConstraintValidator constructor.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

validate($value, Constraint $constraint)

{@inheritdoc}

bool
hasSynchronizedPropertyChanges(ContentEntityInterface $entity, ContentEntityInterface $original, array $synchronized_properties)

Checks whether any synchronized property has changes.

getOriginalEntity(ContentEntityInterface $entity)

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

getOriginalTranslation(ContentEntityInterface $entity, ContentEntityInterface $original)

Returns the original translation.

string[][]
getSynchronizedPropertiesByField(array $field_definitions)

Returns the synchronized properties for every specified field.

Details

__construct(EntityTypeManagerInterface $entity_type_manager, ContentTranslationManagerInterface $content_translation_manager, FieldTranslationSynchronizerInterface $synchronizer)

ContentTranslationSynchronizedFieldsConstraintValidator constructor.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

ContentTranslationManagerInterface $content_translation_manager

The content translation manager.

FieldTranslationSynchronizerInterface $synchronizer

The field translation synchronizer.

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

validate($value, Constraint $constraint)

{@inheritdoc}

Parameters

$value
Constraint $constraint

protected bool hasSynchronizedPropertyChanges(ContentEntityInterface $entity, ContentEntityInterface $original, array $synchronized_properties)

Checks whether any synchronized property has changes.

Parameters

ContentEntityInterface $entity

The entity being validated.

ContentEntityInterface $original

The original unchanged entity.

array $synchronized_properties

An associative array of arrays of synchronized field properties keyed by field name.

Return Value

bool

TRUE if changes in synchronized properties were detected, FALSE otherwise.

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.

protected ContentEntityInterface getOriginalTranslation(ContentEntityInterface $entity, ContentEntityInterface $original)

Returns the original translation.

Parameters

ContentEntityInterface $entity

The entity being validated.

ContentEntityInterface $original

The original entity.

Return Value

ContentEntityInterface

The original entity translation object.

string[][] getSynchronizedPropertiesByField(array $field_definitions)

Returns the synchronized properties for every specified field.

Parameters

array $field_definitions

An array of field definitions.

Return Value

string[][]

An associative array of arrays of field property names keyed by field name.