diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php index 838d060..9519b8d 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php @@ -21,7 +21,6 @@ * label = @Translation("Language"), * description = @Translation("An entity field referencing a language."), * no_ui = TRUE, - * default_widget = "language", * constraints = { * "ComplexData" = { * "value" = {"Length" = {"max" = 12}} diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/LanguageWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/LanguageWidget.php deleted file mode 100644 index 01de5a4..0000000 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/LanguageWidget.php +++ /dev/null @@ -1,45 +0,0 @@ -invoke('language', 'get_default_configuration', array($entity_type, $entity->getType())); - - $element['value'] = $element + array( - '#type' => 'language_select', - '#default_value' => $entity->getUntranslated()->language()->id, - '#languages' => Language::STATE_ALL, - '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], - ); - - return $element; - } - -} diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index ac8a25c..139bf73 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -97,7 +97,7 @@ function testCommentLanguage() { $edit = array( 'title[0][value]' => $title, 'body[0][value]' => $this->randomName(), - 'langcode[0][value]' => $node_langcode, + 'langcode' => $node_langcode, 'comment[0][status]' => CommentItemInterface::OPEN, ); $this->drupalPostForm("node/add/article", $edit, t('Save')); diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php index 5260b5d..093da50 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.php @@ -104,7 +104,7 @@ function testContentTypeLanguageConfiguration() { // Verify language selection appears on the node add form. $this->drupalGet("node/add/{$type2->type}"); // Verify language select list is present. - $this->assertFieldByName('langcode[0][value]', NULL, 'Language select present on the node add form.'); + $this->assertFieldByName('langcode', NULL, 'Language select present on the node add form.'); // Ensure language appears. $this->assertText($name, 'Language present.'); @@ -115,7 +115,7 @@ function testContentTypeLanguageConfiguration() { 'type' => $type2->type, 'title' => $node_title, 'body' => array(array('value' => $node_body)), - 'langcode[0][value]' => $langcode, + 'langcode' => $langcode, ); $node = $this->drupalCreateNode($edit); // Edit the content and ensure correct language is selected. @@ -124,7 +124,7 @@ function testContentTypeLanguageConfiguration() { $this->assertRaw('', 'Correct language selected.'); // Ensure we can change the node language. $edit = array( - 'langcode[0][value]' => 'en', + 'langcode' => 'en', ); $this->drupalPostForm($path, $edit, t('Save')); $this->assertRaw(t('%title has been updated.', array('%title' => $node_title))); diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php index 81579dc..cddf69f 100644 --- a/core/modules/node/lib/Drupal/node/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Entity/Node.php @@ -356,7 +356,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setReadOnly(TRUE); $fields['langcode'] = FieldDefinition::create('language') - ->setLabel(t('Language')) + ->setLabel(t('Language code')) ->setDescription(t('The node language code.')) ->setRevisionable(TRUE); @@ -491,21 +491,6 @@ public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $fields['title'] = clone $base_field_definitions['title']; $fields['title']->setLabel($node_type->title_label); } - - // Set a widget for the 'langcode' base field if Language module is enabled - // and the bundle has multilingual support. - if (\Drupal::moduleHandler()->moduleExists('language')) { - $configuration = language_get_default_configuration('node', $bundle); - if ($configuration['language_show']) { - $fields['langcode'] = clone $base_field_definitions['langcode']; - $fields['langcode']->setDisplayOptions('form', array( - 'type' => 'language', - 'weight' => 0, - )) - ->setDisplayConfigurable('form', TRUE); - } - } - return $fields; } diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 3987024..412ef5a 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -7,12 +7,9 @@ namespace Drupal\node; -use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\Cache; -use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\ContentEntityFormController; use Drupal\Core\Language\Language; -use Drupal\Component\Utility\String; /** * Form controller for the node edit forms. @@ -88,6 +85,16 @@ public function form(array $form, array &$form_state) { '#default_value' => $node->getChangedTime(), ); + $language_configuration = \Drupal::moduleHandler()->invoke('language', 'get_default_configuration', array('node', $node->getType())); + $form['langcode'] = array( + '#title' => t('Language'), + '#type' => 'language_select', + '#default_value' => $node->getUntranslated()->language()->id, + '#languages' => Language::STATE_ALL, + '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], + ); + + $form['advanced'] = array( '#type' => 'vertical_tabs', '#attributes' => array('class' => array('entity-meta')), diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index 040f6ef..4012908 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -88,7 +88,7 @@ protected function createEntity($values, $langcode, $bundle_name = NULL) { $edit = array( 'title[0][value]' => $values['title'][0]['value'], "{$this->fieldName}[0][value]" => $values[$this->fieldName][0]['value'], - 'langcode[0][value]' => $langcode, + 'langcode' => $langcode, ); $this->drupalPostForm('node/add/article', $edit, t('Save and publish')); $this->drupalLogin($this->translator); @@ -186,7 +186,7 @@ function testTranslateLinkContentAdminPage() { $this->drupalLogin($this->administrator); $page = $this->drupalCreateNode(array('type' => 'page')); - $article = $this->drupalCreateNode(array('type' => 'article', 'langcode[0][value]' => $this->langcodes[0])); + $article = $this->drupalCreateNode(array('type' => 'article', 'langcode' => $this->langcodes[0])); // Verify translation links. $this->drupalGet('admin/content'); @@ -201,7 +201,7 @@ function testTranslateLinkContentAdminPage() { function testFieldTranslationForm() { $this->drupalLogin($this->administrator); - $article = $this->drupalCreateNode(array('type' => 'article', 'langcode[0][value]' => 'en')); + $article = $this->drupalCreateNode(array('type' => 'article', 'langcode' => 'en')); // Visit translation page. $this->drupalGet('node/' . $article->id() . '/translations'); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index c031f4c..7cbdd60 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -437,6 +437,40 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') { } /** + * Implements hook_entity_extra_field_info(). + */ +function node_entity_extra_field_info() { + $extra = array(); + $module_language_enabled = \Drupal::moduleHandler()->moduleExists('language'); + $description = t('Node module element'); + + foreach (node_type_get_types() as $bundle) { + // Add the 'language' select if Language module is enabled and the bundle + // has multilingual support. + // Visibility of the ordering of the language selector is the same as on the + // node/add form. + if ($module_language_enabled) { + $configuration = language_get_default_configuration('node', $bundle->type); + if ($configuration['language_show']) { + $extra['node'][$bundle->type]['form']['langcode'] = array( + 'label' => t('Language'), + 'description' => $description, + 'weight' => 0, + ); + } + } + $extra['node'][$bundle->type]['display']['langcode'] = array( + 'label' => t('Language'), + 'description' => $description, + 'weight' => 0, + 'visible' => FALSE, + ); + } + + return $extra; +} + +/** * Updates all nodes of one type to be of another type. * * @param string $old_id