+ if ($entity->isNewRevision()) {
+ if ($entity->isDefaultTranslationAffectedOnly()) {
+ // If changes to untranslatable fields are configured to affect only the
+ // default translation, we need to skip synchronization in pending
+ // revisions, otherwise multiple translations would be affected.
+ if (!$entity->isDefaultRevision()) {
+ return;
+ }
+ // When this mode is enabled, changes to synchronized properties are
+ // allowed only in the default translation, thus we need to make sure this
+ // is always used as source for the synchronization process.
+ else {
+ $sync_langcode = $entity->getUntranslated()->language()->getId();
+ }
+ }
+ elseif ($entity->isDefaultRevision()) {
+ // If a new default revision is being saved, but a newer default
+ // revision was created meanwhile, use any other translation as source
+ // for synchronization, since that will have been merged from the
+ // default revision. In this case the actual language does not matter as
+ // synchronized properties are the same for all the translations in the
+ // default revision.
+ /** @var \Drupal\Core\Entity\ContentEntityInterface $default_revision */
+ $default_revision = $this->entityManager
+ ->getStorage($entity->getEntityTypeId())
+ ->load($entity->id());
+ if ($default_revision->getLoadedRevisionId() !== $entity->getLoadedRevisionId()) {
+ $other_langcodes = array_diff_key($default_revision->getTranslationLanguages(), [$sync_langcode => FALSE]);
+ if ($other_langcodes) {
+ $sync_langcode = key($other_langcodes);
+ }
+ }
+ }
+ }
+