Recently we had a client lose all the content on their homepage because they changed the language of their homepage node, which meant the connection between all the paragraphs on it and the homepage was lost. Now, I realise the 'real' solution is to get paragraphs to handle a language change, but I'm raising this issue because I think it's still a valuable concept: it should be possible to prevent the language of an entity being changed once it has been created.

In D7, the entity_translation contrib module had a (per-bundle) setting for this. I believe it should be an option provided for D8 translations (i.e. core) too. The fact that I have contrib modules that don't handle the situation well should be irrelevant, because even if they did, I would want to avoid the possibility of existing content 'going missing' due to the language being changed. In my opinion, it's a bit of a usability issue, as the language selector looks a bit like a toggle for 'which translation to edit', rather than 'what is the language of this existing content'. That's a separate issue that I'd love to see addressed, but disabling the language selector for existing content (which is what the D7 ET setting did) would go a long way to resolving this as it pushes editors to correctly use the Translate tab instead.

With any luck, I'll get budget to implement a solution in a custom module here (as my client doesn't need it to be configurable), but I'm not entirely sure how this would be best configured within core. The content translation settings page is already an enormous page full of checkboxes, so I'm reluctant to just add another bunch of settings there. I'd be interested to hear whether this is even suitable for core (I think it is because of the usability issue & potential for what can appear to be data loss).

P.S. I've raised this against content_translation, but I don't know if this could also apply to other types of translation (e.g. config) too?

Comments

james.williams created an issue. See original summary.

james.williams’s picture

For anyone looking for a quick solution, this is mine, in a custom module:


use Drupal\Core\Entity\ContentEntityFormInterface;
use Drupal\Core\Entity\ContentEntityInterface;

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $form_object = $form_state->getFormObject();
  if ($form_object instanceof ContentEntityFormInterface) {
    $entity = $form_object->getEntity();
    $op = $form_object->getOperation();

    // Disable the language selector unless this is a new entity. There are too
    // many other things hanging off most content entities that need the
    // language to remain constant (e.g. the paragraphs inline widget).
    // Theoretically, any content entities without those could be allowed to
    // change their language, but we just don't need to support that.
    if ($op == 'edit' || $op == 'default') {
      if ($entity instanceof ContentEntityInterface && !$entity->isNew()) {
        if ($entity->isTranslatable() && count($entity->getTranslationLanguages()) > 1) {
          if ($langcode_key = $entity->getEntityType()->getKey('langcode')) {
            if (isset($form[$langcode_key])) {
              $form[$langcode_key]['widget']['#disabled'] = TRUE;
            }
          }
        }
      }
    }
  }
}

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kunalkursija’s picture

I have come across content editors who by mistake create content in one language say "English", But later on change it to "UND" for some reason. This kind of behavior causes issues like https://www.drupal.org/project/drupal/issues/2961670

I think it would be a plus to disable language switching once the content has been created.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.