protected function ContentTranslationSynchronizedFieldsConstraintValidator::getOriginalTranslation in Drupal 9
Same name and namespace in other branches
- 8 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 193
Class
- ContentTranslationSynchronizedFieldsConstraintValidator
- Checks that synchronized fields are handled correctly in pending revisions.
Namespace
Drupal\content_translation\Plugin\Validation\ConstraintCode
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);
}