getFieldsToSkipFromTranslationChangesCheck example


  protected function realSave() {
    return parent::save();
  }

  /** * {@inheritdoc} */
  protected function getFieldsToSkipFromTranslationChangesCheck() {
    $field_names = parent::getFieldsToSkipFromTranslationChangesCheck();
    // We need to skip the parent entity revision ID, since that will always     // change on every save, otherwise every translation would be marked as     // affected regardless of actual changes.     $field_names[] = 'content_entity_revision_id';
    return $field_names;
  }

}
// Compare field item current values with the original ones to determine     // whether we have changes. If a field is not translatable and the entity is     // translated we skip it because, depending on the use case, it would make     // sense to mark all translations as changed or none of them. We skip also     // computed fields as comparing them with their original values might not be     // 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;
      }
/** * Checks whether an entity has untranslatable field changes. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * A content entity object. * * @return bool * TRUE if untranslatable fields have changes, FALSE otherwise. */
  protected function hasUntranslatableFieldsChanges(ContentEntityInterface $entity) {
    $skip_fields = $this->getFieldsToSkipFromTranslationChangesCheck($entity);
    /** @var \Drupal\Core\Entity\ContentEntityInterface $original */
    if (isset($entity->original)) {
      $original = $entity->original;
    }
    else {
      $original = $this->entityTypeManager
        ->getStorage($entity->getEntityTypeId())
        ->loadRevision($entity->getLoadedRevisionId());
    }

    foreach ($entity->getFieldDefinitions() as $field_name => $definition) {
      
$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'])) {
        $this->entityFormSharedElements($element[$key]$form_state$form);
      }
      else {
        // Ignore non-widget form elements.         if (isset($ignored_types[$element[$key]['#type']])) {
          continue;
        }
        // Elements are considered to be non multilingual by default.
Home | Imprint | This part of the site doesn't use cookies.