You are here

protected function ContentTranslationSynchronizedFieldsConstraintValidator::hasSynchronizedPropertyChanges in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_translation/src/Plugin/Validation/Constraint/ContentTranslationSynchronizedFieldsConstraintValidator.php \Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraintValidator::hasSynchronizedPropertyChanges()

Checks whether any synchronized property has changes.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity being validated.

\Drupal\Core\Entity\ContentEntityInterface $original: The original unchanged entity.

string[][] $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.

1 call to ContentTranslationSynchronizedFieldsConstraintValidator::hasSynchronizedPropertyChanges()
ContentTranslationSynchronizedFieldsConstraintValidator::validate in core/modules/content_translation/src/Plugin/Validation/Constraint/ContentTranslationSynchronizedFieldsConstraintValidator.php

File

core/modules/content_translation/src/Plugin/Validation/Constraint/ContentTranslationSynchronizedFieldsConstraintValidator.php, line 142

Class

ContentTranslationSynchronizedFieldsConstraintValidator
Checks that synchronized fields are handled correctly in pending revisions.

Namespace

Drupal\content_translation\Plugin\Validation\Constraint

Code

protected function hasSynchronizedPropertyChanges(ContentEntityInterface $entity, ContentEntityInterface $original, array $synchronized_properties) {
  foreach ($synchronized_properties as $field_name => $properties) {
    foreach ($properties as $property) {
      $items = $entity
        ->get($field_name)
        ->getValue();
      $original_items = $original
        ->get($field_name)
        ->getValue();
      if (count($items) !== count($original_items)) {
        return TRUE;
      }
      foreach ($items as $delta => $item) {

        // @todo This loose comparison is not fully reliable. Revisit this
        //   after https://www.drupal.org/project/drupal/issues/2941092.
        if ($items[$delta][$property] != $original_items[$delta][$property]) {
          return TRUE;
        }
      }
    }
  }
  return FALSE;
}