diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php index 887c44b..779cdb9 100644 --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -13,6 +13,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\language\Entity\ContentLanguageSettings; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -103,14 +104,16 @@ public function form(array $form, FormStateInterface $form_state) { // names. $form['#attributes']['class'][0] = drupal_html_class('block-' . $block->bundle() . '-form'); + $is_language_alterable = FALSE; if ($this->moduleHandler->moduleExists('language')) { - $language_configuration = language_get_default_configuration('block_content', $block->bundle()); + $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block->bundle()); // Set the correct default language. if ($block->isNew()) { - $language_default = $this->languageManager->getCurrentLanguage($language_configuration['langcode']); + $language_default = $this->languageManager->getCurrentLanguage($language_configuration->getDefaultLangcode()); $block->langcode->value = $language_default->getId(); } + $is_language_alterable = $language_configuration->isLanguageAlterable(); } $form['langcode'] = array( @@ -118,7 +121,7 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'language_select', '#default_value' => $block->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, - '#access' => isset($language_configuration['language_alterable']) && $language_configuration['language_alterable'], + '#access' => $is_language_alterable, ); $form['advanced'] = array( diff --git a/core/modules/block_content/src/BlockContentTypeForm.php b/core/modules/block_content/src/BlockContentTypeForm.php index 3e40858..8cde318 100644 --- a/core/modules/block_content/src/BlockContentTypeForm.php +++ b/core/modules/block_content/src/BlockContentTypeForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\language\Entity\ContentLanguageSettings; /** * Base form for category edit forms. @@ -65,7 +66,7 @@ public function form(array $form, FormStateInterface $form_state) { '#group' => 'additional_settings', ); - $language_configuration = language_get_default_configuration('block_content', $block_type->id()); + $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block_type->id()); $form['language']['language_configuration'] = array( '#type' => 'language_configuration', '#entity_information' => array( diff --git a/core/modules/comment/src/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php index 1f2cb34..db9361a 100644 --- a/core/modules/comment/src/CommentTypeForm.php +++ b/core/modules/comment/src/CommentTypeForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\language\Entity\ContentLanguageSettings; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -132,7 +133,7 @@ public function form(array $form, FormStateInterface $form_state) { '#group' => 'additional_settings', ); - $language_configuration = language_get_default_configuration('comment', $comment_type->id()); + $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', $comment_type->id()); $form['language']['language_configuration'] = array( '#type' => 'language_configuration', '#entity_information' => array( diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php index 9a572ea..342a943 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php @@ -12,6 +12,7 @@ use Drupal\Core\Field\Entity\BaseFieldOverride; use Drupal\Core\Language\Language; use Drupal\field\Entity\FieldConfig; +use Drupal\language\Entity\ContentLanguageSettings; use Drupal\simpletest\WebTestBase; /** @@ -131,9 +132,9 @@ function testSettingsUI() { $this->assertTrue($definitions['name']->isTranslatable() && !$definitions['user_id']->isTranslatable(), 'Base field bundle overrides were correctly altered.'); // Test that language settings are correctly stored. - $language_configuration = language_get_default_configuration('comment', 'comment_article'); - $this->assertEqual($language_configuration['langcode'], 'current_interface', 'The default language for article comments is set to the current interface language.'); - $this->assertTrue($language_configuration['language_alterable'], 'The language selector for article comments is shown.'); + $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_article'); + $this->assertEqual($language_configuration->getDefaultLangcode(), 'current_interface', 'The default language for article comments is set to the current interface language.'); + $this->assertTrue($language_configuration->isLanguageAlterable(), 'The language selector for article comments is shown.'); // Verify language widget appears on comment type form. $this->drupalGet('admin/structure/comment/manage/comment_article'); diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 3154e51..0d58e77 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -295,15 +295,11 @@ function language_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new * The language code. */ function language_get_default_langcode($entity_type, $bundle) { - $configuration = language_get_default_configuration($entity_type, $bundle); - - if (!isset($configuration['langcode'])) { - $configuration['langcode'] = LanguageInterface::LANGCODE_SITE_DEFAULT; - } + $configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle); $default_value = NULL; $language_interface = \Drupal::languageManager()->getCurrentLanguage(); - switch ($configuration['langcode']) { + switch ($configuration->getDefaultLangcode()) { case LanguageInterface::LANGCODE_SITE_DEFAULT: $default_value = \Drupal::languageManager()->getDefaultLanguage()->getId(); break; @@ -329,7 +325,7 @@ function language_get_default_langcode($entity_type, $bundle) { // If we still do not have a default value, just return the value stored in // the configuration; it has to be an actual language code. - return $configuration['langcode']; + return $configuration->getDefaultLangcode(); } /** diff --git a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php index cf40bf0..6a262a3 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php @@ -34,11 +34,11 @@ public function testLanguageConfigurationElement() { $edit['lang_configuration[langcode]'] = 'current_interface'; $edit['lang_configuration[language_alterable]'] = FALSE; $this->drupalPostForm(NULL, $edit, 'Save'); - $lang_conf = language_get_default_configuration('entity_test', 'some_bundle'); + $lang_conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle'); // Check that the settings have been saved. - $this->assertEqual($lang_conf['langcode'], 'current_interface'); - $this->assertFalse($lang_conf['language_alterable']); + $this->assertEqual($lang_conf->getDefaultLangcode(), 'current_interface'); + $this->assertFalse($lang_conf->isLanguageAlterable()); $this->drupalGet('language-tests/language_configuration_element'); $this->assertOptionSelected('edit-lang-configuration-langcode', 'current_interface'); $this->assertNoFieldChecked('edit-lang-configuration-language-alterable'); @@ -48,11 +48,11 @@ public function testLanguageConfigurationElement() { $edit['lang_configuration[langcode]'] = 'authors_default'; $edit['lang_configuration[language_alterable]'] = TRUE; $this->drupalPostForm(NULL, $edit, 'Save'); - $lang_conf = language_get_default_configuration('entity_test', 'some_bundle'); + $lang_conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle'); // Check that the settings have been saved. - $this->assertEqual($lang_conf['langcode'], 'authors_default'); - $this->assertTrue($lang_conf['language_alterable']); + $this->assertEqual($lang_conf->getDefaultLangcode(), 'authors_default'); + $this->assertTrue($lang_conf->isLanguageAlterable()); $this->drupalGet('language-tests/language_configuration_element'); $this->assertOptionSelected('edit-lang-configuration-langcode', 'authors_default'); $this->assertFieldChecked('edit-lang-configuration-language-alterable'); diff --git a/core/modules/language/tests/language_elements_test/src/Form/LanguageConfigurationElement.php b/core/modules/language/tests/language_elements_test/src/Form/LanguageConfigurationElement.php index 16129f7..8dea61c 100644 --- a/core/modules/language/tests/language_elements_test/src/Form/LanguageConfigurationElement.php +++ b/core/modules/language/tests/language_elements_test/src/Form/LanguageConfigurationElement.php @@ -8,6 +8,7 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\language\Entity\ContentLanguageSettings; /** * A form containing a language configuration element. @@ -25,7 +26,7 @@ public function getFormID() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { - $conf = language_get_default_configuration('entity_test', 'some_bundle'); + $conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle'); $form['lang_configuration'] = array( '#type' => 'language_configuration', diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 37fea66..99b036f 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -15,6 +15,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; +use Drupal\language\Entity\ContentLanguageSettings; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Database\StatementInterface; use Drupal\Core\Database\Query\AlterableInterface; @@ -382,8 +383,8 @@ function node_entity_extra_field_info() { // 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_alterable']) { + $configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', $bundle->type); + if ($configuration->isLanguageAlterable()) { $extra['node'][$bundle->type]['form']['langcode'] = array( 'label' => t('Language'), 'description' => $description, diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php index 9335b1b..8a0f2a6 100644 --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\language\Entity\ContentLanguageSettings; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -166,7 +167,7 @@ public function form(array $form, FormStateInterface $form_state) { '#group' => 'additional_settings', ); - $language_configuration = language_get_default_configuration('node', $type->id()); + $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', $type->id()); $form['language']['language_configuration'] = array( '#type' => 'language_configuration', '#entity_information' => array( diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index ade34f5..47291f8 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; +use Drupal\language\Entity\ContentLanguageSettings; /** * Base for controller for taxonomy term edit forms. @@ -28,13 +29,17 @@ public function form(array $form, FormStateInterface $form_state) { $form_state->set(['taxonomy', 'parent'], $parent); $form_state->set(['taxonomy', 'vocabulary'], $vocabulary); - $language_configuration = $this->moduleHandler->moduleExists('language') ? language_get_default_configuration('taxonomy_term', $vocabulary->id()) : FALSE; + $is_language_alterable = false; + if ($this->moduleHandler->moduleExists('language')) { + $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary->id()); + $is_language_alterable = $language_configuration->isLanguageAlterable(); + } $form['langcode'] = array( '#type' => 'language_select', '#title' => $this->t('Language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $term->getUntranslated()->language()->getId(), - '#access' => !empty($language_configuration['language_alterable']), + '#access' => $is_language_alterable, ); $form['relations'] = array( diff --git a/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php b/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php index 9298756..8ad0526 100644 --- a/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php +++ b/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\language\Entity\ConfigurableLanguage; +use Drupal\language\Entity\ContentLanguageSettings; /** * Tests the language functionality for vocabularies. @@ -89,7 +90,7 @@ function testVocabularyDefaultLanguageForTerms() { $this->assertResponse(200, 'The vocabulary has been created.'); // Check that the language settings were saved. - $language_settings = language_get_default_configuration('taxonomy_term', $edit['vid']); + $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']); $this->assertEqual($language_settings['langcode'], 'bb', 'The langcode was saved.'); $this->assertTrue($language_settings['language_alterable'], 'The visibility setting was saved.'); @@ -105,7 +106,7 @@ function testVocabularyDefaultLanguageForTerms() { $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save')); // And check again the settings and also the interface. - $language_settings = language_get_default_configuration('taxonomy_term', $vid); + $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid); $this->assertEqual($language_settings['langcode'], 'aa', 'The langcode was saved.'); $this->assertFalse($language_settings['language_alterable'], 'The visibility setting was saved.'); @@ -122,7 +123,7 @@ function testVocabularyDefaultLanguageForTerms() { $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save')); // Check that we have the new settings. - $new_settings = language_get_default_configuration('taxonomy_term', $vid); + $new_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid); $this->assertEqual($new_settings['langcode'], 'authors_default', 'The langcode was saved.'); $this->assertFalse($new_settings['language_alterable'], 'The new visibility setting was saved.'); } diff --git a/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php index 08bf93b..dc8b6b1 100644 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; +use Drupal\language\Entity\ContentLanguageSettings; /** * Base form for vocabulary edit forms. @@ -73,7 +74,7 @@ public function form(array $form, FormStateInterface $form_state) { 'entity_type' => 'taxonomy_term', 'bundle' => $vocabulary->id(), ), - '#default_value' => language_get_default_configuration('taxonomy_term', $vocabulary->id()), + '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary->id()), ); } // Set the hierarchy to "multiple parents" by default. This simplifies the