diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/LanguageSelectWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/LanguageSelectWidget.php index 05f2aa1..567276c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/LanguageSelectWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/LanguageSelectWidget.php @@ -11,7 +11,6 @@ use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\TypedData\TranslatableInterface; /** * Plugin implementation of the 'Language' widget. diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index 3bd1b38..1aae420 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -144,27 +144,33 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En } } - // Disable languages for existing translations, so it is not possible to - // switch this node to some language which is already in the translation - // set. - $langcode_key = $this->entityType->getKey('langcode') ?: 'langcode'; - $language_widget = NULL; - if (isset($form[$langcode_key]['widget'][0]['value']['#type'])) { - $language_widget = &$form[$langcode_key]['widget'][0]['value']; - if (!$is_translation && $language_widget['#type'] == 'language_select' && $has_translations) { + // Locate the language widget. + $language_field = $this->entityType->getKey('langcode') ?: 'langcode'; + if (isset($form[$language_field])) { + $language_widget = &$form[$language_field]; + } + + // If we are editing the source entity, force the list of languages so that + // it is not possible to switch to a language for which a translation + // already exists. Note that this will only work if the widget is structured + // like \Drupal\Core\Field\Plugin\Field\FieldWidget\LanguageSelectWidget. + if (isset($language_widget['widget'][0]['value']) && !$is_translation && $has_translations) { + $language_select = &$language_widget['widget'][0]['value']; + if ($language_select['#type'] == 'language_select') { $options = array(); foreach (language_list(LanguageInterface::STATE_CONFIGURABLE) as $language) { + // Show the current language, and the languages for which no + // translation already exists. if (empty($translations[$language->getId()]) || $language->getId() == $entity_langcode) { -// $form['langcode']['#options'][$language->getId()] = $language->getName(); - $options[$language->getId()] = $language->getName(); + $options[$language->getId()] = $language->getName(); } } - $language_widget['#options'] = $options; + $language_select['#options'] = $options; } } if ($is_translation) { - if ($language_widget) { + if (isset($language_widget)) { $language_widget['#access'] = FALSE; } @@ -276,8 +282,8 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En '#default_value' => $new_translation ? '' : format_date($date, 'custom', 'Y-m-d H:i:s O'), ); - if ($language_widget) { - $form[$langcode_key]['#multilingual'] = TRUE; + if (isset($language_widget)) { + $language_widget['#multilingual'] = TRUE; } $form['#process'][] = array($this, 'entityFormSharedElements');