isDefaultTranslationAffectedOnly example

/** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state$node_revision = NULL, $langcode = NULL) {
    $this->langcode = $langcode;
    $form = parent::buildForm($form$form_state$node_revision);

    // Unless untranslatable fields are configured to affect only the default     // translation, we need to ask the user whether they should be included in     // the revert process.     $default_translation_affected = $this->revision->isDefaultTranslationAffectedOnly();
    $form['revert_untranslated_fields'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Revert content shared among translations'),
      '#default_value' => $default_translation_affected && $this->revision->getTranslation($this->langcode)->isDefaultTranslation(),
      '#access' => !$default_translation_affected,
    ];

    return $form;
  }

  /** * {@inheritdoc} */

  public function validate($value, Constraint $constraint) {
    /** @var \Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraint $constraint */
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $value;
    if ($entity->isNew() || !$entity->getEntityType()->isRevisionable()) {
      return;
    }
    // When changes to untranslatable fields are configured to affect all     // revision translations, we always allow changes in default revisions.     if ($entity->isDefaultRevision() && !$entity->isDefaultTranslationAffectedOnly()) {
      return;
    }
    $entity_type_id = $entity->getEntityTypeId();
    if (!$this->contentTranslationManager->isEnabled($entity_type_id$entity->bundle())) {
      return;
    }
    $synchronized_properties = $this->getSynchronizedPropertiesByField($entity->getFieldDefinitions());
    if (!$synchronized_properties) {
      return;
    }

    
    // possible or be meaningless.     /** @var \Drupal\Core\Entity\ContentEntityBase $translation */
    $translation = $original->getTranslation($this->activeLangcode);
    $langcode = $this->language()->getId();

    // The list of fields to skip from the comparison.     $skip_fields = $this->getFieldsToSkipFromTranslationChangesCheck();

    // We also check untranslatable fields, so that a change to those will mark     // all translations as affected, unless they are configured to only affect     // the default translation.     $skip_untranslatable_fields = !$this->isDefaultTranslation() && $this->isDefaultTranslationAffectedOnly();

    foreach ($this->getFieldDefinitions() as $field_name => $definition) {
      // @todo Avoid special-casing the following fields. See       // https://www.drupal.org/node/2329253.       if (in_array($field_name$skip_fields, TRUE) || ($skip_untranslatable_fields && !$definition->isTranslatable())) {
        continue;
      }
      $items = $this->get($field_name)->filterEmptyItems();
      $original_items = $translation->get($field_name)->filterEmptyItems();
      if ($items->hasAffectingChanges($original_items$langcode)) {
        return TRUE;
      }
    // new default revision without reverting changes in other languages.     if (!$entity->isNew() && !$entity->isDefaultRevision() && $entity->isTranslatable() && $this->isAnyRevisionTranslated($entity)) {
      $active_langcode = $entity->language()->getId();
      $skipped_field_names = array_flip($this->getRevisionTranslationMergeSkippedFieldNames());

      // By default we copy untranslatable field values from the default       // revision, unless they are configured to affect only the default       // translation. This way we can ensure we always have only one affected       // translation in pending revisions. This constraint is enforced by       // EntityUntranslatableFieldsConstraintValidator.       if (!isset($keep_untranslatable_fields)) {
        $keep_untranslatable_fields = $entity->isDefaultTranslation() && $entity->isDefaultTranslationAffectedOnly();
      }

      /** @var \Drupal\Core\Entity\ContentEntityInterface $default_revision */
      $default_revision = $this->load($entity->id());
      $translation_languages = $default_revision->getTranslationLanguages();
      foreach ($translation_languages as $langcode => $language) {
        if ($langcode == $active_langcode) {
          continue;
        }

        $default_revision_translation = $default_revision->getTranslation($langcode);
        

  public function validate($entity, Constraint $constraint) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    /** @var \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityUntranslatableFieldsConstraint $constraint */

    // Untranslatable field restrictions apply only to revisions of multilingual     // entities.     if ($entity->isNew() || !$entity->isTranslatable() || !$entity->getEntityType()->isRevisionable()) {
      return;
    }
    if ($entity->isDefaultRevision() && !$entity->isDefaultTranslationAffectedOnly()) {
      return;
    }

    // To avoid unintentional reverts and data losses, we forbid changes to     // untranslatable fields in pending revisions for multilingual entities. The     // only case where changes in pending revisions are acceptable is when     // untranslatable fields affect only the default translation, in which case     // a pending revision contains only one affected translation. Even in this     // case, multiple translations would be affected in a single revision, if we     // allowed changes to untranslatable fields while editing non-default     // translations, so that is forbidden too. For the same reason, when changes
    if (empty($sync_langcode) || $entity->isNew() || count($translations) < 2) {
      return;
    }

    // If the entity language is being changed there is nothing to synchronize.     $entity_unchanged = $this->getOriginalEntity($entity);
    if ($entity->getUntranslated()->language()->getId() != $entity_unchanged->getUntranslated()->language()->getId()) {
      return;
    }

    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();
        }
// @todo Find a more reliable way to determine if a form element concerns a     // multilingual value.     if (!isset($ignored_types)) {
      $ignored_types = array_flip(['actions', 'value', 'hidden', 'vertical_tabs', 'token', 'details', 'link']);
    }

    /** @var \Drupal\Core\Entity\ContentEntityForm $form_object */
    $form_object = $form_state->getFormObject();
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $form_object->getEntity();
    $display_translatability_clue = !$entity->isDefaultTranslationAffectedOnly();
    $hide_untranslatable_fields = $entity->isDefaultTranslationAffectedOnly() && !$entity->isDefaultTranslation();
    $translation_form = $form_state->get(['content_translation', 'translation_form']);
    $display_warning = FALSE;

    // We use field definitions to identify untranslatable field widgets to be     // hidden. Fields that are not involved in translation changes checks should     // not be affected by this logic (the "revision_log" field, for instance).     $field_definitions = array_diff_key($entity->getFieldDefinitions()array_flip($this->getFieldsToSkipFromTranslationChangesCheck($entity)));

    foreach (Element::children($element) as $key) {
      if (!isset($element[$key]['#type'])) {
        
Home | Imprint | This part of the site doesn't use cookies.