diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php index 887c44b..0197f9f 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,22 +104,12 @@ public function form(array $form, FormStateInterface $form_state) { // names. $form['#attributes']['class'][0] = drupal_html_class('block-' . $block->bundle() . '-form'); - if ($this->moduleHandler->moduleExists('language')) { - $language_configuration = language_get_default_configuration('block_content', $block->bundle()); - - // Set the correct default language. - if ($block->isNew()) { - $language_default = $this->languageManager->getCurrentLanguage($language_configuration['langcode']); - $block->langcode->value = $language_default->getId(); - } - } - $form['langcode'] = array( '#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $block->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, - '#access' => isset($language_configuration['language_alterable']) && $language_configuration['language_alterable'], + '#access' => FALSE, ); $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/CommentForm.php b/core/modules/comment/src/CommentForm.php index bf81415..cc8b9d4 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -17,6 +17,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\language\Entity\ContentLanguageSettings; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -161,13 +162,12 @@ public function form(array $form, FormStateInterface $form_state) { $form['author']['name']['#attributes']['data-drupal-default-value'] = $this->config('user.settings')->get('anonymous'); } - $language_configuration = \Drupal::moduleHandler()->invoke('language', 'get_default_configuration', array('comment', $comment->getTypeId())); $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', '#default_value' => $comment->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL, - '#access' => isset($language_configuration['language_alterable']) && $language_configuration['language_alterable'], + '#access' => FALSE, ); // Add author email and homepage fields depending on the current user. 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/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php index 41c7f37..a84fb8e 100644 --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -98,13 +98,12 @@ public function form(array $form, FormStateInterface $form_state) { $form['preview']['message'] = $this->entityManager->getViewBuilder('contact_message')->view($message, 'full'); } - $language_configuration = $this->moduleHandler->invoke('language', 'get_default_configuration', array('contact_message', $message->getContactForm()->id())); $form['langcode'] = array( '#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $message->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL, - '#access' => isset($language_configuration['language_alterable']) && $language_configuration['language_alterable'], + '#access' => FALSE, ); $form['name'] = 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..554a529 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\String; +use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -228,33 +229,6 @@ function language_save_default_configuration($entity_type, $bundle, $values = ar } /** - * Returns the language configuration stored for an entity type and bundle. - * - * @param string $entity_type - * A string representing the entity type. - * @param string $bundle - * A string representing the bundle. - * - * @return array - * An array with the following keys: - * - langcode: the language code. - * - language_alterable: if the language element is hidden or not. - * - * @deprecated in Drupal 8.0.x-dev, will be removed in Drupal 9.0.0. - * Call - * \Drupal\language\Entity\ContentLanguageSettings::loadByEntityTypeBundle - * instead. - */ -function language_get_default_configuration($entity_type, $bundle) { - $default = ['langcode' => LanguageInterface::LANGCODE_SITE_DEFAULT, 'language_alterable' => false]; - $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle); - if ($config) { - $default = ['langcode' => $config->getDefaultLangcode(), 'language_alterable' => $config->isLanguageAlterable()]; - } - return $default; -} - -/** * Clears the default language configuration for an entity type and bundle. * * @param string $entity_type @@ -295,15 +269,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 +299,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(); } /** @@ -524,6 +494,23 @@ function language_form_system_regional_settings_alter(&$form, FormStateInterface } /** + * Implements hook_form_alter(). + */ +function language_form_alter(&$form, FormStateInterface $form_state, $form_id) { + $form_object = $form_state->getFormObject(); + if ($form_object instanceof ContentEntityFormInterface && isset($form['langcode'])) { + /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ + $entity_type_id = $form_object->getEntity()->getEntityTypeId(); + $bundle = $form_object->getEntity()->bundle(); + $entity_type = Drupal::entityManager()->getDefinition($entity_type_id); + if ($entity_type->isTranslatable()) { + $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle); + $form['langcode']['#access'] = $language_configuration->isLanguageAlterable(); + } + } +} + +/** * Form submission handler for system_regional_settings(). * * @see language_form_system_regional_settings_alter() diff --git a/core/modules/language/src/Element/LanguageConfiguration.php b/core/modules/language/src/Element/LanguageConfiguration.php index 5bc736e..ad998f7 100644 --- a/core/modules/language/src/Element/LanguageConfiguration.php +++ b/core/modules/language/src/Element/LanguageConfiguration.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Render\Element\FormElement; +use Drupal\language\Entity\ContentLanguageSettings; /** * Provides language element configuration. @@ -40,24 +41,26 @@ public static function processLanguageConfiguration(&$element, FormStateInterfac // Avoid validation failure since we are moving the '#options' key in the // nested 'language' select element. unset($element['#options']); + /** @var ContentLanguageSettings $default_config */ + $default_config = $element['#default_value']; $element['langcode'] = array( '#type' => 'select', '#title' => t('Default language'), '#options' => $options + static::getDefaultOptions(), '#description' => t('Explanation of the language options is found on the languages list page.', array('@languages_list_page' => \Drupal::url('language.admin_overview'))), - '#default_value' => isset($element['#default_value']['langcode']) ? $element['#default_value']['langcode'] : NULL, + '#default_value' => ($default_config != NULL) ? $default_config->getDefaultLangcode() : LanguageInterface::LANGCODE_SITE_DEFAULT, ); $element['language_alterable'] = array( '#type' => 'checkbox', '#title' => t('Show language selector on create and edit pages'), - '#default_value' => isset($element['#default_value']['language_alterable']) ? $element['#default_value']['language_alterable'] : NULL, + '#default_value' => ($default_config != NULL) ? $default_config->isLanguageAlterable() : FALSE, ); // Add the entity type and bundle information to the form if they are set. // They will be used, in the submit handler, to generate the names of the - // variables that will store the settings and are a way to uniquely identify - // the entity. + // configuration entities that will store the settings and are a way to uniquely + // identify the entity. $language = $form_state->get('language') ?: []; $language += array( $element['#name'] => array( diff --git a/core/modules/language/src/Form/ContentLanguageSettingsForm.php b/core/modules/language/src/Form/ContentLanguageSettingsForm.php index 63ffd7e..1e89850 100644 --- a/core/modules/language/src/Form/ContentLanguageSettingsForm.php +++ b/core/modules/language/src/Form/ContentLanguageSettingsForm.php @@ -80,8 +80,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { if (!$config->isDefaultConfiguration()) { $default[$entity_type_id] = $entity_type_id; } - $language_configuration[$entity_type_id][$bundle]['language_alterable'] = $config->isLanguageAlterable(); - $language_configuration[$entity_type_id][$bundle]['langcode'] = $config->getDefaultLangcode(); + $language_configuration[$entity_type_id][$bundle] = $config; } } diff --git a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php index cf40bf0..35ca41c 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'); @@ -130,18 +130,20 @@ public function testNodeTypeUpdate() { ); $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type')); // Check the language default configuration for the articles. - $configuration = language_get_default_configuration('node', 'article'); - $uuid = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')->uuid(); - $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_alterable' => TRUE), 'The default language configuration has been saved on the Article content type.'); + $configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article'); + $uuid = $configuration->uuid(); + $this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been saved on the Article content type.'); + $this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been saved on the Article content type.'); // Rename the article content type. $edit = array( 'type' => 'article_2' ); $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type')); // Check that we still have the settings for the new node type. - $configuration = language_get_default_configuration('node', 'article_2'); - $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_alterable' => TRUE), 'The default language configuration has been kept on the new Article content type.'); - $this->assertEqual(ContentLanguageSettings::loadByEntityTypeBundle('node', 'article_2')->uuid(), $uuid, 'The language configuration uuid has been kept on the new Article content type.'); + $configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article_2'); + $this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the new Article content type.'); + $this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the new Article content type.'); + $this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the new Article content type.'); } /** @@ -163,18 +165,20 @@ public function testTaxonomyVocabularyUpdate() { $this->drupalPostForm('admin/structure/taxonomy/manage/country', $edit, t('Save')); // Check the language default configuration. - $configuration = language_get_default_configuration('taxonomy_term', 'country'); - $uuid = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'country')->uuid(); - $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_alterable' => TRUE), 'The default language configuration has been saved on the Country vocabulary.'); + $configuration = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'country'); + $uuid = $configuration->uuid(); + $this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been saved on the Country vocabulary.'); + $this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been saved on the Country vocabulary.'); // Rename the vocabulary. $edit = array( 'vid' => 'nation' ); $this->drupalPostForm('admin/structure/taxonomy/manage/country', $edit, t('Save')); // Check that we still have the settings for the new vocabulary. - $configuration = language_get_default_configuration('taxonomy_term', 'nation'); - $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_alterable' => TRUE), 'The default language configuration has been kept on the new Country vocabulary.'); - $this->assertEqual(ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'nation')->uuid(), $uuid, 'The language configuration uuid has been kept on the new Country vocabulary.'); + $configuration = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'nation'); + $this->assertEqual($configuration->getDefaultLangcode(), 'current_interface', 'The default language configuration has been kept on the new Country vocabulary.'); + $this->assertTrue($configuration->isLanguageAlterable(), 'The alterable language configuration has been kept on the new Country vocabulary.'); + $this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the new Country vocabulary.'); } } 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/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index a9d4da1..d67c5d1 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -257,19 +257,12 @@ public function form(array $form, FormStateInterface $form_state) { '#weight' => -2, ); - $language_configuration = $this->moduleHandler->invoke('language', 'get_default_configuration', array('menu_link_content', 'menu_link_content')); - if ($this->entity->isNew()) { - $default_language = isset($language_configuration['langcode']) ? $language_configuration['langcode'] : $this->languageManager->getDefaultLanguage()->getId(); - } - else { - $default_language = $this->entity->getUntranslated()->language()->getId(); - } $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', - '#default_value' => $default_language, + '#default_value' => $this->entity->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL, - '#access' => !empty($language_configuration['language_alterable']), + '#access' => FALSE, ); $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId(); 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/NodeForm.php b/core/modules/node/src/NodeForm.php index 9bb7ee1..f9fb2ee 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\language\Entity\ContentLanguageSettings; use Drupal\user\TempStoreFactory; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\user\Entity\User; @@ -108,13 +109,12 @@ public function form(array $form, FormStateInterface $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()->getId(), '#languages' => LanguageInterface::STATE_ALL, - '#access' => isset($language_configuration['language_alterable']) && $language_configuration['language_alterable'], + '#access' => FALSE, ); $form['advanced'] = array( 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/system/entity.api.php b/core/modules/system/entity.api.php index cfb41c7..189e8a2 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Render\Element; +use Drupal\language\Entity\ContentLanguageSettings; /** * @defgroup entity_crud Entity CRUD, editing, and view hooks @@ -1911,8 +1912,8 @@ function hook_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']['language'] = array( 'label' => t('Language'), 'description' => $description, diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index ade34f5..b10bccb 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,12 @@ 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; $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' => FALSE, ); $form['relations'] = array( diff --git a/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php b/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php index 9298756..c172257 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,9 +90,9 @@ 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']); - $this->assertEqual($language_settings['langcode'], 'bb', 'The langcode was saved.'); - $this->assertTrue($language_settings['language_alterable'], 'The visibility setting was saved.'); + $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']); + $this->assertEqual($language_settings->getDefaultLangcode(), 'bb', 'The langcode was saved.'); + $this->assertTrue($language_settings->isLanguageAlterable(), 'The visibility setting was saved.'); // Check that the correct options are selected in the interface. $this->assertOptionSelected('edit-default-language-langcode', 'bb', 'The correct default language for the terms of this vocabulary is selected.'); @@ -105,9 +106,9 @@ 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); - $this->assertEqual($language_settings['langcode'], 'aa', 'The langcode was saved.'); - $this->assertFalse($language_settings['language_alterable'], 'The visibility setting was saved.'); + $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid); + $this->assertEqual($language_settings->getDefaultLangcode(), 'aa', 'The langcode was saved.'); + $this->assertFalse($language_settings->isLanguageAlterable(), 'The visibility setting was saved.'); $this->drupalGet('admin/structure/taxonomy/manage/' . $vid); $this->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.'); @@ -122,8 +123,8 @@ 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); - $this->assertEqual($new_settings['langcode'], 'authors_default', 'The langcode was saved.'); - $this->assertFalse($new_settings['language_alterable'], 'The new visibility setting was saved.'); + $new_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid); + $this->assertEqual($new_settings->getDefaultLangcode(), 'authors_default', 'The langcode was saved.'); + $this->assertFalse($new_settings->isLanguageAlterable(), '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