function ContentTranslationSynchronizedFieldsConstraintValidator::getOriginalTranslation

Same name and namespace in other branches
  1. 9 core/modules/content_translation/src/Plugin/Validation/Constraint/ContentTranslationSynchronizedFieldsConstraintValidator.php \Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraintValidator::getOriginalTranslation()
  2. 8.9.x core/modules/content_translation/src/Plugin/Validation/Constraint/ContentTranslationSynchronizedFieldsConstraintValidator.php \Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraintValidator::getOriginalTranslation()
  3. 10 core/modules/content_translation/src/Plugin/Validation/Constraint/ContentTranslationSynchronizedFieldsConstraintValidator.php \Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraintValidator::getOriginalTranslation()

Returns the original translation.

Parameters

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

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

Return value

\Drupal\Core\Entity\ContentEntityInterface The original entity translation object.

1 call to ContentTranslationSynchronizedFieldsConstraintValidator::getOriginalTranslation()
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 194

Class

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

Namespace

Drupal\content_translation\Plugin\Validation\Constraint

Code

protected function getOriginalTranslation(ContentEntityInterface $entity, ContentEntityInterface $original) {
    // If the language of the default translation is changing, the original
    // translation will be the same as the original entity, but they won't
    // necessarily have the same langcode.
    if ($entity->isDefaultTranslation() && $original->language()
        ->getId() !== $entity->language()
        ->getId()) {
        return $original;
    }
    $langcode = $entity->language()
        ->getId();
    if ($original->hasTranslation($langcode)) {
        $original_langcode = $langcode;
    }
    else {
        $metadata = $this->contentTranslationManager
            ->getTranslationMetadata($entity);
        $original_langcode = $metadata->getSource();
    }
    return $original->getTranslation($original_langcode);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.