diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php index 769a7f3..6b5efed 100644 --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -118,7 +118,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_show']) && $language_configuration['language_show'], + '#access' => isset($language_configuration['language_exposed']) && $language_configuration['language_exposed'], ); $form['advanced'] = array( diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index 35e033d..bdb1422 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -167,7 +167,7 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'language_select', '#default_value' => $comment->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL, - '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], + '#access' => isset($language_configuration['language_exposed']) && $language_configuration['language_exposed'], ); // Add author email and homepage fields depending on the current user. diff --git a/core/modules/comment/src/Tests/CommentLanguageTest.php b/core/modules/comment/src/Tests/CommentLanguageTest.php index 746aea4..fb824d0 100644 --- a/core/modules/comment/src/Tests/CommentLanguageTest.php +++ b/core/modules/comment/src/Tests/CommentLanguageTest.php @@ -44,7 +44,7 @@ protected function setUp() { $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); // Set "Article" content type to use multilingual support. - $edit = array('language_configuration[language_show]' => TRUE); + $edit = array('language_configuration[language_exposed]' => TRUE); $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type')); // Enable content language negotiation UI. diff --git a/core/modules/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php index 0e280cb..ec69c16 100644 --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -104,7 +104,7 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'language_select', '#default_value' => $message->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL, - '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], + '#access' => isset($language_configuration['language_exposed']) && $language_configuration['language_exposed'], ); $form['name'] = array( diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 231dbc6..54a2621 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -267,7 +267,7 @@ function content_translation_form_language_content_settings_validate(array $form } $values = $bundle_settings['settings']['language']; - if (empty($values['language_show']) && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) { + if (empty($values['language_exposed']) && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) { foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $language) { $locked_languages[] = $language->getName(); } diff --git a/core/modules/content_translation/content_translation.admin.js b/core/modules/content_translation/content_translation.admin.js index 109cb34..cb2670f 100644 --- a/core/modules/content_translation/content_translation.admin.js +++ b/core/modules/content_translation/content_translation.admin.js @@ -90,7 +90,7 @@ var $settings = $bundleSettings.nextUntil('.bundle-settings'); var $fieldSettings = $settings.filter('.field-settings'); if ($target.is(':checked')) { - $bundleSettings.find('.operations :input[name$="[language_show]"]').prop('checked', true); + $bundleSettings.find('.operations :input[name$="[language_exposed]"]').prop('checked', true); $fieldSettings.find('.translatable :input').prop('checked', true); $settings.show(); } diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index ffa5d89..a363a70 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -675,7 +675,7 @@ function content_translation_language_configuration_element_process(array $eleme function content_translation_language_configuration_element_validate($element, FormStateInterface $form_state, array $form) { $key = $form_state->get(['content_translation', 'key']); $values = $form_state->getValue($key); - if (!$values['language_show'] && $values['content_translation'] && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) { + if (!$values['language_exposed'] && $values['content_translation'] && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) { foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $language) { $locked_languages[] = $language->getName(); } diff --git a/core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php b/core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php index b8234b3..8792cd8 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php @@ -102,7 +102,7 @@ protected function setUp() { // Enable content translation. $configuration = array( 'langcode' => language_default()->getId(), - 'language_show' => TRUE, + 'language_exposed' => TRUE, ); language_save_default_configuration('node', $this->bundle, $configuration); // Create a translator user. diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php index 98ea255..6732352 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php @@ -84,7 +84,7 @@ function testSettingsUI() { $edit = array( 'entity_types[comment]' => TRUE, 'settings[comment][comment_article][settings][language][langcode]' => Language::LANGCODE_NOT_SPECIFIED, - 'settings[comment][comment_article][settings][language][language_show]' => FALSE, + 'settings[comment][comment_article][settings][language][language_exposed]' => FALSE, 'settings[comment][comment_article][translatable]' => TRUE, 'settings[comment][comment_article][fields][comment_body]' => TRUE, ); @@ -96,7 +96,7 @@ function testSettingsUI() { $edit = array( 'entity_types[comment]' => TRUE, 'settings[comment][comment_article][settings][language][langcode]' => 'current_interface', - 'settings[comment][comment_article][settings][language][language_show]' => TRUE, + 'settings[comment][comment_article][settings][language][language_exposed]' => TRUE, 'settings[comment][comment_article][translatable]' => TRUE, 'settings[comment][comment_article][fields][comment_body]' => TRUE, // Override both comment subject fields to untranslatable. @@ -130,7 +130,7 @@ function testSettingsUI() { // 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_show'], 'The language selector for article comments is shown.'); + $this->assertTrue($language_configuration['language_exposed'], 'The language selector for article comments is shown.'); // Verify language widget appears on comment type form. $this->drupalGet('admin/structure/comment/manage/comment_article'); @@ -153,7 +153,7 @@ function testSettingsUI() { $edit = array( 'entity_types[node]' => TRUE, 'settings[node][article][settings][language][langcode]' => 'current_interface', - 'settings[node][article][settings][language][language_show]' => TRUE, + 'settings[node][article][settings][language][language_exposed]' => TRUE, 'settings[node][article][translatable]' => TRUE, 'settings[node][article][fields][title]' => TRUE ); @@ -250,7 +250,7 @@ function testFieldTranslatableSettingsUI() { // Note: this field is not translatable when enable bundle translatability. $edit = array( 'entity_types[node]' => TRUE, - 'settings[node][article][settings][language][language_show]' => TRUE, + 'settings[node][article][settings][language][language_exposed]' => TRUE, 'settings[node][article][translatable]' => TRUE, 'settings[node][article][fields][article_text]' => TRUE, ); diff --git a/core/modules/language/config/schema/language.schema.yml b/core/modules/language/config/schema/language.schema.yml index 2633fdc..ef6cb5a 100644 --- a/core/modules/language/config/schema/language.schema.yml +++ b/core/modules/language/config/schema/language.schema.yml @@ -101,34 +101,25 @@ language.entity.*: type: boolean label: 'Locked' -language.settings: - type: mapping - label: 'Language settings' +language.content_settings.*.*: + type: config_entity + label: 'Content Language Settings' mapping: - entities: - type: sequence - label: 'Entity type' - sequence: - - type: sequence - label: 'Bundle' - sequence: - - type: mapping - label: 'Custom language settings' - mapping: - language: - type: mapping - label: 'Custom language settings' - mapping: - default_configuration: - type: mapping - label: 'Default language' - mapping: - langcode: - type: string - label: 'Default language' - language_show: - type: boolean - label: 'Show language selector on create and edit pages' + id: + type: string + label: 'ID' + entity_type: + type: string + label: 'Entity Type ID' + bundle: + type: string + label: 'Bundle' + default_langcode: + type: string + label: 'Default language' + language_exposed: + type: boolean + label: 'Show language selector on create and edit pages' condition.plugin.language: type: condition.plugin diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 68126f6..948623c 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -5,10 +5,12 @@ * Add language handling functionality to Drupal. */ +use Drupal\Component\Utility\String; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\language\ConfigurableLanguageInterface; +use Drupal\language\Entity\ContentLanguageSettings; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback; @@ -193,10 +195,17 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_ * @param array $values * An array holding the values to be saved having the following keys: * - langcode: the language code. - * - language_show: if the language element should be hidden or not. + * - language_exposed: if the language element should be hidden or not. */ function language_save_default_configuration($entity_type, $bundle, $values = array()) { - \Drupal::config('language.settings')->set(language_get_default_configuration_settings_key($entity_type, $bundle), array('langcode' => $values['langcode'], 'language_show' => $values['language_show']))->save(); + $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle); + if (isset($values['langcode'])) { + $config->setDefaultLangcode(String::checkPlain($values['langcode'])); + } + if (isset($values['language_exposed'])) { + $config->setLanguageExposed(String::checkPlain($values['language_exposed'])); + } + $config->save(); } /** @@ -210,15 +219,11 @@ function language_save_default_configuration($entity_type, $bundle, $values = ar * @return array * An array with the following keys: * - langcode: the language code. - * - language_show: if the language element is hidden or not. + * - language_exposed: if the language element is hidden or not. */ function language_get_default_configuration($entity_type, $bundle) { - $configuration = \Drupal::config('language.settings')->get(language_get_default_configuration_settings_key($entity_type, $bundle)); - if (is_null($configuration)) { - $configuration = array(); - } - $configuration += array('langcode' => LanguageInterface::LANGCODE_SITE_DEFAULT, 'language_show' => FALSE); - return $configuration; + $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle); + return ['langcode' => $config->getDefaultLangcode(), 'language_exposed' => $config->getLanguageExposed()]; } /** @@ -230,28 +235,10 @@ function language_get_default_configuration($entity_type, $bundle) { * A string representing the bundle. */ function language_clear_default_configuration($entity_type, $bundle) { - \Drupal::config('language.settings')->clear(language_get_default_configuration_settings_key($entity_type, $bundle))->save(); -} - -/** - * Returns the root name of the variables used to store the configuration. - * - * Based on the entity type and bundle, the variables used to store the - * configuration will have a common root name. - * - * @param string $entity_type - * A string representing the entity type. - * @param string $bundle - * A string representing the bundle. - * - * @return string - * The root name of the variables. - */ -function language_get_default_configuration_settings_key($entity_type, $bundle) { - // Replace all the characters that are not letters, numbers or "_" with "_". - $entity_type = preg_replace('/[^0-9a-zA-Z_]/', "_", $entity_type); - $bundle = preg_replace('/[^0-9a-zA-Z_]/', "_", $bundle); - return 'entities.' . $entity_type . '.' . $bundle . '.language.default_configuration'; + $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle); + if (!$config->isNew()) { + $config->delete(); + } } /** diff --git a/core/modules/language/src/Element/LanguageConfiguration.php b/core/modules/language/src/Element/LanguageConfiguration.php index 5ae8b00..35ea5a5 100644 --- a/core/modules/language/src/Element/LanguageConfiguration.php +++ b/core/modules/language/src/Element/LanguageConfiguration.php @@ -48,10 +48,10 @@ public static function processLanguageConfiguration(&$element, FormStateInterfac '#default_value' => isset($element['#default_value']['langcode']) ? $element['#default_value']['langcode'] : NULL, ); - $element['language_show'] = array( + $element['language_exposed'] = array( '#type' => 'checkbox', '#title' => t('Show language selector on create and edit pages'), - '#default_value' => isset($element['#default_value']['language_show']) ? $element['#default_value']['language_show'] : NULL, + '#default_value' => isset($element['#default_value']['language_exposed']) ? $element['#default_value']['language_exposed'] : NULL, ); // Add the entity type and bundle information to the form if they are set. diff --git a/core/modules/language/src/Entity/ContentLanguageSettings.php b/core/modules/language/src/Entity/ContentLanguageSettings.php new file mode 100644 index 0000000..a93a892 --- /dev/null +++ b/core/modules/language/src/Entity/ContentLanguageSettings.php @@ -0,0 +1,156 @@ +entity_type . '.' . $this->bundle; + } + + /** + * Sets the default language code. + * + * @param string $default_langcode + * + * @return $this; + */ + public function setDefaultLangcode($default_langcode) { + $this->default_langcode = $default_langcode; + + return $this; + } + + /** + * Gets the default language code. + * + * @return string + */ + public function getDefaultLangcode() { + return $this->default_langcode; + } + + /** + * Sets if the language must be exposed or not. + * + * @param bool $language_show + * + * @return $this + */ + public function setLanguageExposed($language_show) { + $this->language_exposed = $language_show; + + return $this; + } + + /** + * Checks if the language must be exposed or not. + * + * @return bool + */ + public function getLanguageExposed() { + return $this->language_exposed; + } + + /** + * {@inheritdoc} + */ + public function preSave(EntityStorageInterface $storage) { + if ($this->isNew()) { + $this->id = $this->id(); + } + parent::preSave($storage); + } + + /** + * Checks if this config object differs from default values in any property. + * + * @return bool + * True if any of the properties are the default values. False otherwise. + */ + public function differsFromDefaultConfiguration() { + return ($this->language_exposed || $this->default_langcode != LanguageInterface::LANGCODE_SITE_DEFAULT); + } + + /** + * Loads a content language config entity based on the entity type and bundle. + * + * @param string $entity_type_id + * ID of the entity type. + * @param string $bundle + * Bundle name. + * + * @return static + * The content language config entity if one exists. Otherwise, returns + * sensible default values. + */ + public static function loadByEntityTypeBundle($entity_type_id, $bundle) { + $config = \Drupal::entityManager()->getStorage('language_content_settings')->load($entity_type_id . '.' . $bundle); + if ($config == NULL) { + $config = ContentLanguageSettings::create(['entity_type' => $entity_type_id, 'bundle' => $bundle]); + } + return $config; + } + +} diff --git a/core/modules/language/src/Form/ContentLanguageSettingsForm.php b/core/modules/language/src/Form/ContentLanguageSettingsForm.php index a415379..a381ee1 100644 --- a/core/modules/language/src/Form/ContentLanguageSettingsForm.php +++ b/core/modules/language/src/Form/ContentLanguageSettingsForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; +use Drupal\language\Entity\ContentLanguageSettings; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -76,11 +77,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Check whether we have any custom setting. foreach ($bundles[$entity_type_id] as $bundle => $bundle_info) { - $conf = language_get_default_configuration($entity_type_id, $bundle); - if (!empty($conf['language_show']) || $conf['langcode'] != LanguageInterface::LANGCODE_SITE_DEFAULT) { + $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle); + if ($config->differsFromDefaultConfiguration()) { $default[$entity_type_id] = $entity_type_id; } - $language_configuration[$entity_type_id][$bundle] = $conf; + $language_configuration[$entity_type_id][$bundle]['language_exposed'] = $config->getLanguageExposed(); + $language_configuration[$entity_type_id][$bundle]['langcode'] = $config->getDefaultLangcode(); } } @@ -145,16 +147,14 @@ public function buildForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $config = $this->config('language.settings'); foreach ($form_state->getValue('settings') as $entity_type => $entity_settings) { foreach ($entity_settings as $bundle => $bundle_settings) { - $config->set(language_get_default_configuration_settings_key($entity_type, $bundle), array( - 'langcode' => $bundle_settings['settings']['language']['langcode'], - 'language_show' => $bundle_settings['settings']['language']['language_show'], - )); + $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle); + $config->setDefaultLangcode($bundle_settings['settings']['language']['langcode']) + ->setLanguageExposed($bundle_settings['settings']['language']['language_exposed']) + ->save(); } } - $config->save(); drupal_set_message($this->t('Settings successfully updated.')); } diff --git a/core/modules/language/src/Tests/EntityDefaultLanguageTest.php b/core/modules/language/src/Tests/EntityDefaultLanguageTest.php index 4c5f3b2..bab5eed 100644 --- a/core/modules/language/src/Tests/EntityDefaultLanguageTest.php +++ b/core/modules/language/src/Tests/EntityDefaultLanguageTest.php @@ -121,7 +121,7 @@ protected function createContentType($name, $langcode) { $content_type->save(); language_save_default_configuration('node', $name, array( 'langcode' => $langcode, - 'language_show' => FALSE, + 'language_exposed' => FALSE, )); } diff --git a/core/modules/language/src/Tests/LanguageConfigSchemaTest.php b/core/modules/language/src/Tests/LanguageConfigSchemaTest.php index aeddc2b..8c71358 100644 --- a/core/modules/language/src/Tests/LanguageConfigSchemaTest.php +++ b/core/modules/language/src/Tests/LanguageConfigSchemaTest.php @@ -56,20 +56,20 @@ function testValidLanguageConfigSchema() { // Enable translation for menu link. $edit['entity_types[menu_link_content]'] = TRUE; - $edit['settings[menu_link_content][menu_link_content][settings][language][language_show]'] = TRUE; + $edit['settings[menu_link_content][menu_link_content][settings][language][language_exposed]'] = TRUE; // Enable translation for user. $edit['entity_types[user]'] = TRUE; - $edit['settings[user][user][settings][language][language_show]'] = TRUE; + $edit['settings[user][user][settings][language][language_exposed]'] = TRUE; $edit['settings[user][user][settings][language][langcode]'] = 'en'; $this->drupalPostForm($settings_path, $edit, t('Save configuration')); - $config_data = \Drupal::config('language.settings')->get(); + $config_data = \Drupal::config('language.content_settings.menu_link_content.menu_link_content')->get(); // Make sure configuration saved correctly. - $this->assertTrue($config_data['entities']['menu_link_content']['menu_link_content']['language']['default_configuration']['language_show']); + $this->assertTrue($config_data['language_exposed']); - $this->assertConfigSchema(\Drupal::service('config.typed'), 'language.settings', $config_data); + $this->assertConfigSchema(\Drupal::service('config.typed'), 'language.content_settings.menu_link_content.menu_link_content', $config_data); } } diff --git a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php index 9b2d82d..a1f4d15 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php @@ -31,30 +31,30 @@ class LanguageConfigurationElementTest extends WebTestBase { public function testLanguageConfigurationElement() { $this->drupalGet('language-tests/language_configuration_element'); $edit['lang_configuration[langcode]'] = 'current_interface'; - $edit['lang_configuration[language_show]'] = FALSE; + $edit['lang_configuration[language_exposed]'] = FALSE; $this->drupalPostForm(NULL, $edit, 'Save'); $lang_conf = language_get_default_configuration('some_custom_type', 'some_bundle'); // Check that the settings have been saved. $this->assertEqual($lang_conf['langcode'], 'current_interface'); - $this->assertFalse($lang_conf['language_show']); + $this->assertFalse($lang_conf['language_exposed']); $this->drupalGet('language-tests/language_configuration_element'); $this->assertOptionSelected('edit-lang-configuration-langcode', 'current_interface'); - $this->assertNoFieldChecked('edit-lang-configuration-language-show'); + $this->assertNoFieldChecked('edit-lang-configuration-language-exposed'); // Reload the page and save again. $this->drupalGet('language-tests/language_configuration_element'); $edit['lang_configuration[langcode]'] = 'authors_default'; - $edit['lang_configuration[language_show]'] = TRUE; + $edit['lang_configuration[language_exposed]'] = TRUE; $this->drupalPostForm(NULL, $edit, 'Save'); $lang_conf = language_get_default_configuration('some_custom_type', 'some_bundle'); // Check that the settings have been saved. $this->assertEqual($lang_conf['langcode'], 'authors_default'); - $this->assertTrue($lang_conf['language_show']); + $this->assertTrue($lang_conf['language_exposed']); $this->drupalGet('language-tests/language_configuration_element'); $this->assertOptionSelected('edit-lang-configuration-langcode', 'authors_default'); - $this->assertFieldChecked('edit-lang-configuration-language-show'); + $this->assertFieldChecked('edit-lang-configuration-language-exposed'); } /** @@ -70,12 +70,12 @@ public function testDefaultLangcode() { } // Fixed language. - language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'bb', 'language_show' => TRUE)); + language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'bb', 'language_exposed' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); $this->assertEqual($langcode, 'bb'); // Current interface. - language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'current_interface', 'language_show' => TRUE)); + language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'current_interface', 'language_exposed' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); $language_interface = \Drupal::languageManager()->getCurrentLanguage(); $this->assertEqual($langcode, $language_interface->getId()); @@ -87,7 +87,7 @@ public function testDefaultLangcode() { $this->assertTrue($configurable_language->isDefault(), 'The en language entity is flagged as the default language.'); \Drupal::config('system.site')->set('langcode', 'cc')->save(); - language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => LanguageInterface::LANGCODE_SITE_DEFAULT, 'language_show' => TRUE)); + language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => LanguageInterface::LANGCODE_SITE_DEFAULT, 'language_exposed' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); $this->assertEqual($langcode, 'cc'); @@ -107,7 +107,7 @@ public function testDefaultLangcode() { $some_user->preferred_langcode = 'bb'; $some_user->save(); $this->drupalLogin($some_user); - language_save_default_configuration('custom_type', 'some_bundle', array('langcode' => 'authors_default', 'language_show' => TRUE)); + language_save_default_configuration('custom_type', 'some_bundle', array('langcode' => 'authors_default', 'language_exposed' => TRUE)); $this->drupalGet('language-tests/language_configuration_element_test'); $this->assertOptionSelected('edit-langcode', 'bb'); } @@ -125,12 +125,12 @@ public function testNodeTypeUpdate() { $this->drupalLogin($admin_user); $edit = array( 'language_configuration[langcode]' => 'current_interface', - 'language_configuration[language_show]' => TRUE, + 'language_configuration[language_exposed]' => TRUE, ); $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'); - $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_show' => TRUE), 'The default language configuration has been saved on the Article content type.'); + $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_exposed' => TRUE), 'The default language configuration has been saved on the Article content type.'); // Rename the article content type. $edit = array( 'type' => 'article_2' @@ -138,6 +138,6 @@ public function testNodeTypeUpdate() { $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_show' => TRUE), 'The default language configuration has been kept on the new Article content type.'); + $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_exposed' => TRUE), 'The default language configuration has been kept on the new Article content type.'); } } diff --git a/core/modules/locale/src/Tests/LocaleContentTest.php b/core/modules/locale/src/Tests/LocaleContentTest.php index 1bef062..d15e9cb 100644 --- a/core/modules/locale/src/Tests/LocaleContentTest.php +++ b/core/modules/locale/src/Tests/LocaleContentTest.php @@ -84,7 +84,7 @@ public function testContentTypeLanguageConfiguration() { $this->drupalGet("admin/structure/types/manage/{$type2->type}"); $this->assertText(t('Language settings'), 'Multilingual support widget present on content type configuration form.'); $edit = array( - 'language_configuration[language_show]' => TRUE, + 'language_configuration[language_exposed]' => TRUE, ); $this->drupalPostForm("admin/structure/types/manage/{$type2->type}", $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => $type2->name))); @@ -156,7 +156,7 @@ public function testContentTypeDirLang() { // Set the content type to use multilingual support. $this->drupalGet("admin/structure/types/manage/{$type->type}"); $edit = array( - 'language_configuration[language_show]' => TRUE, + 'language_configuration[language_exposed]' => TRUE, ); $this->drupalPostForm("admin/structure/types/manage/{$type->type}", $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => $type->name))); diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index 4fb93b2..55b89c6 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -269,7 +269,7 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'language_select', '#default_value' => $default_language, '#languages' => Language::STATE_ALL, - '#access' => !empty($language_configuration['language_show']), + '#access' => !empty($language_configuration['language_exposed']), ); $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId(); diff --git a/core/modules/menu_ui/src/Tests/MenuLanguageTest.php b/core/modules/menu_ui/src/Tests/MenuLanguageTest.php index f74fb09..c453ba5 100644 --- a/core/modules/menu_ui/src/Tests/MenuLanguageTest.php +++ b/core/modules/menu_ui/src/Tests/MenuLanguageTest.php @@ -60,7 +60,7 @@ function testMenuLanguage() { 'langcode' => 'aa', ); $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save')); - language_save_default_configuration('menu_link_content', 'menu_link_content', array('langcode' => 'bb', 'language_show' => TRUE)); + language_save_default_configuration('menu_link_content', 'menu_link_content', array('langcode' => 'bb', 'language_exposed' => TRUE)); // Check menu language. $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The menu language was correctly selected.'); @@ -85,7 +85,7 @@ function testMenuLanguage() { )); // Edit menu link default, changing it to cc. - language_save_default_configuration('menu_link_content', 'menu_link_content', array('langcode' => 'cc', 'language_show' => TRUE)); + language_save_default_configuration('menu_link_content', 'menu_link_content', array('langcode' => 'cc', 'language_exposed' => TRUE)); // Add a menu link. $link_title = $this->randomString(); @@ -122,7 +122,7 @@ function testMenuLanguage() { $this->assertOptionSelected('edit-langcode', 'bb', 'The menu link language was correctly selected.'); // Edit menu to hide the language select on menu link item add. - language_save_default_configuration('menu_link_content', 'menu_link_content', array('langcode' => 'cc', 'language_show' => FALSE)); + language_save_default_configuration('menu_link_content', 'menu_link_content', array('langcode' => 'cc', 'language_exposed' => FALSE)); // Check that the language selector is not available on menu link add page. $this->drupalGet("admin/structure/menu/manage/$menu_name/add"); diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 36c7d75..f1a645e 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -159,8 +159,7 @@ function node_uninstall() { foreach ($types as $config_name) { $type = \Drupal::config($config_name)->get('type'); if (\Drupal::moduleHandler()->moduleExists('language')) { - $key = language_get_default_configuration_settings_key('node', $type); - \Drupal::config('language.settings')->clear($key)->save(); + language_clear_default_configuration('node', $type); } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d65d59d..49482b6 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -391,7 +391,7 @@ function node_entity_extra_field_info() { // node/add form. if ($module_language_enabled) { $configuration = language_get_default_configuration('node', $bundle->type); - if ($configuration['language_show']) { + if ($configuration['language_exposed']) { $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 7f9ef84..3f1a205 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -114,7 +114,7 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'language_select', '#default_value' => $node->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, - '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], + '#access' => isset($language_configuration['language_exposed']) && $language_configuration['language_exposed'], ); $form['advanced'] = array( diff --git a/core/modules/node/src/Tests/NodeFieldMultilingualTest.php b/core/modules/node/src/Tests/NodeFieldMultilingualTest.php index d00ffcd..b5e5e5b 100644 --- a/core/modules/node/src/Tests/NodeFieldMultilingualTest.php +++ b/core/modules/node/src/Tests/NodeFieldMultilingualTest.php @@ -46,7 +46,7 @@ protected function setUp() { // Set "Basic page" content type to use multilingual support. $edit = array( - 'language_configuration[language_show]' => TRUE, + 'language_configuration[language_exposed]' => TRUE, ); $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.'); diff --git a/core/modules/node/src/Tests/NodeTranslationUITest.php b/core/modules/node/src/Tests/NodeTranslationUITest.php index b5fd27a..fd02266 100644 --- a/core/modules/node/src/Tests/NodeTranslationUITest.php +++ b/core/modules/node/src/Tests/NodeTranslationUITest.php @@ -42,7 +42,7 @@ protected function setUp() { // Display the language selector. $this->drupalLogin($this->administrator); - $edit = array('language_configuration[language_show]' => TRUE); + $edit = array('language_configuration[language_exposed]' => TRUE); $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type')); $this->drupalLogin($this->translator); } diff --git a/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php b/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php index 971d091..204808f 100644 --- a/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php +++ b/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php @@ -39,7 +39,7 @@ protected function setUp() { function testNodeTypeInitialLanguageDefaults() { $this->drupalGet('admin/structure/types/manage/article'); $this->assertOptionSelected('edit-language-configuration-langcode', LanguageInterface::LANGCODE_SITE_DEFAULT, 'The default initial language is the site default.'); - $this->assertNoFieldChecked('edit-language-configuration-language-show', 'Language selector is hidden by default.'); + $this->assertNoFieldChecked('edit-language-configuration-language-exposed', 'Language selector is hidden by default.'); // Tests if the language field cannot be rearranged on the manage fields tab. $this->drupalGet('admin/structure/types/manage/article/fields'); @@ -62,7 +62,7 @@ function testNodeTypeInitialLanguageDefaults() { // Tests the initial language after changing the site default language. // First unhide the language selector. $edit = array( - 'language_configuration[language_show]' => TRUE, + 'language_configuration[language_exposed]' => TRUE, ); $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type')); $this->drupalGet('node/add/article'); diff --git a/core/modules/path/src/Tests/PathLanguageTest.php b/core/modules/path/src/Tests/PathLanguageTest.php index df198e1..4fdaa5d 100644 --- a/core/modules/path/src/Tests/PathLanguageTest.php +++ b/core/modules/path/src/Tests/PathLanguageTest.php @@ -56,7 +56,7 @@ protected function setUp() { 'settings[node][page][translatable]' => 1, 'settings[node][page][fields][path]' => 1, 'settings[node][page][fields][body]' => 1, - 'settings[node][page][settings][language][language_show]' => 1, + 'settings[node][page][settings][language][language_exposed]' => 1, ); $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration')); diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 5974440..e5f0f6c 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -1912,7 +1912,7 @@ function hook_entity_extra_field_info() { // node/add form. if ($module_language_enabled) { $configuration = language_get_default_configuration('node', $bundle->type); - if ($configuration['language_show']) { + if ($configuration['language_exposed']) { $extra['node'][$bundle->type]['form']['language'] = array( 'label' => t('Language'), 'description' => $description, diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php index 59da34d..cc5c6d6 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php @@ -80,7 +80,7 @@ function testEntityFormLanguage() { // Enable language selector. $this->drupalGet('admin/structure/types/manage/page'); - $edit = array('language_configuration[language_show]' => TRUE, 'language_configuration[langcode]' => LanguageInterface::LANGCODE_NOT_SPECIFIED); + $edit = array('language_configuration[language_exposed]' => TRUE, 'language_configuration[langcode]' => LanguageInterface::LANGCODE_NOT_SPECIFIED); $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.'); diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index 2136b0f..b026ee1 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -34,7 +34,7 @@ public function form(array $form, FormStateInterface $form_state) { '#title' => $this->t('Language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $term->getUntranslated()->language()->getId(), - '#access' => !empty($language_configuration['language_show']), + '#access' => !empty($language_configuration['language_exposed']), ); $form['relations'] = array( diff --git a/core/modules/taxonomy/src/Tests/TermLanguageTest.php b/core/modules/taxonomy/src/Tests/TermLanguageTest.php index 71cacee..cfd9b0c 100644 --- a/core/modules/taxonomy/src/Tests/TermLanguageTest.php +++ b/core/modules/taxonomy/src/Tests/TermLanguageTest.php @@ -41,7 +41,7 @@ protected function setUp() { function testTermLanguage() { // Configure the vocabulary to not hide the language selector. $edit = array( - 'default_language[language_show]' => TRUE, + 'default_language[language_exposed]' => TRUE, ); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); @@ -77,7 +77,7 @@ function testDefaultTermLanguage() { // default language of the terms fixed. $edit = array( 'default_language[langcode]' => 'bb', - 'default_language[language_show]' => TRUE, + 'default_language[language_exposed]' => TRUE, ); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); @@ -86,7 +86,7 @@ function testDefaultTermLanguage() { // Make the default language of the terms to be the current interface. $edit = array( 'default_language[langcode]' => 'current_interface', - 'default_language[language_show]' => TRUE, + 'default_language[language_exposed]' => TRUE, ); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); $this->drupalGet('aa/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); @@ -99,7 +99,7 @@ function testDefaultTermLanguage() { \Drupal::config('system.site')->set('langcode', 'cc')->save(); $edit = array( 'default_language[langcode]' => LanguageInterface::LANGCODE_SITE_DEFAULT, - 'default_language[language_show]' => TRUE, + 'default_language[language_exposed]' => TRUE, ); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); diff --git a/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php b/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php index 0b400e7..e09389a 100644 --- a/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php +++ b/core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php @@ -78,7 +78,7 @@ function testVocabularyDefaultLanguageForTerms() { 'name' => $this->randomMachineName(), 'vid' => drupal_strtolower($this->randomMachineName()), 'default_language[langcode]' => 'bb', - 'default_language[language_show]' => TRUE, + 'default_language[language_exposed]' => TRUE, ); $vid = $edit['vid']; $this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save')); @@ -90,39 +90,39 @@ function testVocabularyDefaultLanguageForTerms() { // 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_show'], 'The visibility setting was saved.'); + $this->assertTrue($language_settings['language_exposed'], '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.'); - $this->assertFieldChecked('edit-default-language-language-show', 'Show language selection option is checked.'); + $this->assertFieldChecked('edit-default-language-language-exposed', 'Show language selection option is checked.'); // Edit the vocabulary and check that the new settings are updated. $edit = array( 'default_language[langcode]' => 'aa', - 'default_language[language_show]' => FALSE, + 'default_language[language_exposed]' => FALSE, ); $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_show'], 'The visibility setting was saved.'); + $this->assertFalse($language_settings['language_exposed'], '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.'); - $this->assertNoFieldChecked('edit-default-language-language-show', 'Show language selection option is not checked.'); + $this->assertNoFieldChecked('edit-default-language-language-exposed', 'Show language selection option is not checked.'); // Check that language settings are changed after editing vocabulary. $edit = array( 'name' => $this->randomMachineName(), 'default_language[langcode]' => 'authors_default', - 'default_language[language_show]' => FALSE, + 'default_language[language_exposed]' => FALSE, ); $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_show'], 'The new visibility setting was saved.'); + $this->assertFalse($new_settings['language_exposed'], 'The new visibility setting was saved.'); } } diff --git a/core/modules/views/src/Tests/SearchMultilingualTest.php b/core/modules/views/src/Tests/SearchMultilingualTest.php index 97213c3..7dc09e1 100644 --- a/core/modules/views/src/Tests/SearchMultilingualTest.php +++ b/core/modules/views/src/Tests/SearchMultilingualTest.php @@ -45,7 +45,7 @@ public function testMultilingualSearchFilter() { // Create a content type and make it translatable. $type = $this->drupalCreateContentType(); $edit = array( - 'language_configuration[language_show]' => TRUE, + 'language_configuration[language_exposed]' => TRUE, ); $this->drupalPostForm('admin/structure/types/manage/' . $type->type, $edit, t('Save content type')); $edit = array(