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 e08a2e6..b93e7e9 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/LanguageSelectWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/LanguageSelectWidget.php @@ -11,6 +11,7 @@ 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. @@ -29,10 +30,14 @@ class LanguageSelectWidget extends WidgetBase { * {@inheritdoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { + $entity = $items->getEntity(); + if ($entity instanceof TranslatableInterface) { + $entity = $entity->getUntranslated(); + } $element['value'] = array( '#title' => $this->t('Language'), '#type' => 'language_select', - '#default_value' => $items->getEntity()->language()->getId(), + '#default_value' => $entity->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, ); return $element; diff --git a/core/modules/aggregator/src/Tests/FeedLanguageTest.php b/core/modules/aggregator/src/Tests/FeedLanguageTest.php index 0d4e481..6cb6b8f 100644 --- a/core/modules/aggregator/src/Tests/FeedLanguageTest.php +++ b/core/modules/aggregator/src/Tests/FeedLanguageTest.php @@ -43,6 +43,8 @@ protected function setUp() { $language->save(); $this->langcodes[$i] = $language->id(); } + + language_save_default_configuration('aggregator_feed', 'aggregator_feed', array('langcode' => 'site_default', 'language_show' => TRUE)); } /** @@ -52,8 +54,8 @@ public function testFeedLanguage() { /** @var \Drupal\aggregator\FeedInterface[] $feeds */ $feeds = array(); // Create feeds. - $feeds[1] = $this->createFeed(NULL, array('langcode' => $this->langcodes[1])); - $feeds[2] = $this->createFeed(NULL, array('langcode' => $this->langcodes[2])); + $feeds[1] = $this->createFeed(NULL, array('langcode[0][value]' => $this->langcodes[1])); + $feeds[2] = $this->createFeed(NULL, array('langcode[0][value]' => $this->langcodes[2])); // Make sure that the language has been assigned. $this->assertEqual($feeds[1]->language()->id, $this->langcodes[1]); diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 102c67a..5822832 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -381,9 +381,10 @@ function content_translation_form_alter(array &$form, FormStateInterface $form_s // Handle fields shared between translations when there is at least one // translation available or a new one is being created. if (!$entity->isNew() && (!isset($translations[$form_langcode]) || count($translations) > 1)) { - foreach ($entity->getFieldDefinitions() as $property_name => $definition) { - if (isset($form[$property_name])) { - $form[$property_name]['#multilingual'] = $definition->isTranslatable(); + $langcode_key = $entity->getEntityType()->getKey('langcode') ?: 'langcode'; + foreach ($entity->getFieldDefinitions() as $field_name => $definition) { + if (isset($form[$field_name]) && $field_name != $langcode_key) { + $form[$field_name]['#multilingual'] = $definition->isTranslatable(); } } } diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index b619036..e83ea78 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -147,19 +147,23 @@ 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. - $language_widget = isset($form['langcode']) && $form['langcode']['#type'] == 'language_select'; - if ($language_widget && $has_translations) { - $form['langcode']['#options'] = array(); + $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 && $language_widget['#type'] == 'language_select' && $has_translations) { + $language_widget['#options'] = array(); foreach (language_list(LanguageInterface::STATE_CONFIGURABLE) as $language) { if (empty($translations[$language->id]) || $language->id == $entity_langcode) { - $form['langcode']['#options'][$language->id] = $language->name; + $language_widget['#options'][$language->id] = $language->name; } } } if ($is_translation) { if ($language_widget) { - $form['langcode']['#access'] = FALSE; + $language_widget['#access'] = FALSE; } // Replace the delete button with the delete translation one. @@ -271,7 +275,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En ); if ($language_widget) { - $form['langcode']['#multilingual'] = TRUE; + $form[$langcode_key]['#multilingual'] = TRUE; } $form['#process'][] = array($this, 'entityFormSharedElements'); diff --git a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php index 3e14a6a..a7c8c6d 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php @@ -163,6 +163,7 @@ protected function setupBundle() { protected function enableTranslation() { // Enable translation for the current entity type and ensure the change is // picked up. + language_save_default_configuration($this->entityTypeId, $this->bundle, array('langcode' => 'site_default', 'language_show' => TRUE)); content_translation_set_config($this->entityTypeId, $this->bundle, 'enabled', TRUE); drupal_static_reset(); \Drupal::entityManager()->clearCachedDefinitions(); diff --git a/core/modules/content_translation/src/Tests/ContentTranslationUITest.php b/core/modules/content_translation/src/Tests/ContentTranslationUITest.php index 58d0c59..24da9e6 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationUITest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITest.php @@ -8,7 +8,6 @@ namespace Drupal\content_translation\Tests; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageInterface;