diff --git a/core/includes/update.inc b/core/includes/update.inc index 9a4606e..4ae0302 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -747,7 +747,7 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) { $default = isset($default) ? $default : \Drupal::languageManager()->getDefaultLanguage(); // Rename the default language. $default->name = t("Site's default language (@lang_name)", array('@lang_name' => $default->name)); - $filtered_languages['site_default'] = $default; + $filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default; } foreach ($languages as $langcode => $language) { diff --git a/core/lib/Drupal/Core/Language/LanguageInterface.php b/core/lib/Drupal/Core/Language/LanguageInterface.php index f2e58f3..bb83e28 100644 --- a/core/lib/Drupal/Core/Language/LanguageInterface.php +++ b/core/lib/Drupal/Core/Language/LanguageInterface.php @@ -52,6 +52,11 @@ const LANGCODE_DEFAULT = 'x-default'; /** + * Language code referring to site's default language. + */ + const LANGCODE_SITE_DEFAULT = 'site_default'; + + /** * The language state when referring to configurable languages. */ const STATE_CONFIGURABLE = 1; diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index 35a3fad..2d15a95 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -150,7 +150,7 @@ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { // if we're acting on a global object, so clone the object first. $default = clone $default; $default->name = $this->t("Site's default language (@lang_name)", array('@lang_name' => $default->name)); - $filtered_languages['site_default'] = $default; + $filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default; } foreach ($this->languages as $id => $language) { diff --git a/core/modules/language/language.module b/core/modules/language/language.module index d60d42e..cd1d45bc 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -189,7 +189,7 @@ function language_element_info() { */ function language_configuration_element_default_options() { $language_options = array( - 'site_default' => t("Site's default language (!language)", array('!language' => \Drupal::languageManager()->getDefaultLanguage()->name)), + LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (!language)", array('!language' => \Drupal::languageManager()->getDefaultLanguage()->name)), 'current_interface' => t('Current interface language'), 'authors_default' => t("Author's preferred language"), ); @@ -299,7 +299,7 @@ function language_get_default_configuration($entity_type, $bundle) { if (is_null($configuration)) { $configuration = array(); } - $configuration += array('langcode' => 'site_default', 'language_show' => FALSE); + $configuration += array('langcode' => LanguageInterface::LANGCODE_SITE_DEFAULT, 'language_show' => FALSE); return $configuration; } @@ -361,13 +361,13 @@ function language_get_default_langcode($entity_type, $bundle) { $configuration = language_get_default_configuration($entity_type, $bundle); if (!isset($configuration['langcode'])) { - $configuration['langcode'] = 'site_default'; + $configuration['langcode'] = LanguageInterface::LANGCODE_SITE_DEFAULT; } $default_value = NULL; $language_interface = \Drupal::languageManager()->getCurrentLanguage(); switch ($configuration['langcode']) { - case 'site_default': + case LanguageInterface::LANGCODE_SITE_DEFAULT: $default_value = \Drupal::languageManager()->getDefaultLanguage()->id; break; diff --git a/core/modules/language/src/Form/ContentLanguageSettingsForm.php b/core/modules/language/src/Form/ContentLanguageSettingsForm.php index 34ce092..6361879 100644 --- a/core/modules/language/src/Form/ContentLanguageSettingsForm.php +++ b/core/modules/language/src/Form/ContentLanguageSettingsForm.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Language\LanguageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -76,7 +77,7 @@ 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'] != 'site_default') { + if (!empty($conf['language_show']) || $conf['langcode'] != LanguageInterface::LANGCODE_SITE_DEFAULT) { $default[$entity_type_id] = $entity_type_id; } $language_configuration[$entity_type_id][$bundle] = $conf; diff --git a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php index 6815955..9e0d285 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php @@ -7,6 +7,7 @@ namespace Drupal\language\Tests; +use Drupal\Core\Language\LanguageInterface; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\simpletest\WebTestBase; @@ -86,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' => 'site_default', 'language_show' => TRUE)); + language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => LanguageInterface::LANGCODE_SITE_DEFAULT, 'language_show' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); $this->assertEqual($langcode, 'cc'); diff --git a/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php b/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php index 81bf814..971d091 100644 --- a/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php +++ b/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\LanguageInterface; + /** * Tests node type initial language settings. * @@ -36,7 +38,7 @@ protected function setUp() { */ function testNodeTypeInitialLanguageDefaults() { $this->drupalGet('admin/structure/types/manage/article'); - $this->assertOptionSelected('edit-language-configuration-langcode', 'site_default', 'The default initial language is the site default.'); + $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.'); // Tests if the language field cannot be rearranged on the manage fields tab. diff --git a/core/modules/node/src/Tests/Views/NodeLanguageTest.php b/core/modules/node/src/Tests/Views/NodeLanguageTest.php index 290d9d8..0947a1e 100644 --- a/core/modules/node/src/Tests/Views/NodeLanguageTest.php +++ b/core/modules/node/src/Tests/Views/NodeLanguageTest.php @@ -9,6 +9,7 @@ use Drupal\field\Entity\FieldStorageConfig; use Drupal\language\Entity\ConfigurableLanguage; +use Drupal\views\Plugin\views\PluginBase; /** * Tests node language fields, filters, and sorting. @@ -180,7 +181,7 @@ public function testLanguages() { // filter is set to the site default language instead. This should just // show the English nodes, no matter what the content language is. $config = \Drupal::config('views.view.frontpage'); - $config->set('display.default.display_options.filters.langcode.value', array('***LANGUAGE_site_default***' => '***LANGUAGE_site_default***')); + $config->set('display.default.display_options.filters.langcode.value', array(PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT => PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT)); $config->save(); foreach ($this->node_titles as $langcode => $titles) { $this->drupalGet(($langcode == 'en' ? '' : "$langcode/") . 'node'); diff --git a/core/modules/taxonomy/src/Tests/TermLanguageTest.php b/core/modules/taxonomy/src/Tests/TermLanguageTest.php index cb64143..4264c0b 100644 --- a/core/modules/taxonomy/src/Tests/TermLanguageTest.php +++ b/core/modules/taxonomy/src/Tests/TermLanguageTest.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\LanguageInterface; use Drupal\language\Entity\ConfigurableLanguage; /** @@ -97,7 +98,7 @@ function testDefaultTermLanguage() { // language is still correctly selected. \Drupal::config('system.site')->set('langcode', 'cc')->save(); $edit = array( - 'default_language[langcode]' => 'site_default', + 'default_language[langcode]' => LanguageInterface::LANGCODE_SITE_DEFAULT, 'default_language[language_show]' => TRUE, ); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save')); diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index a92027d..7363d28 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -52,6 +52,13 @@ const INCLUDE_NEGOTIATED = 16; /** + * Query string to indicate the site default language. + * + * @see \Drupal\Core\Language\LanguageInterface::LANGCODE_DEFAULT + */ + const VIEWS_QUERY_LANGUAGE_SITE_DEFAULT = '***LANGUAGE_site_default***'; + + /** * Options for this plugin will be held here. * * @var array @@ -402,13 +409,13 @@ protected function listLanguages($flags = LanguageInterface::STATE_ALL) { $list = array(); // The Language Manager class takes care of the STATE_SITE_DEFAULT case. - // It comes in with ID set to 'site_default'. Since this is not a real - // language, surround it by '***LANGUAGE_...***', like the negotiated - // languages below. + // It comes in with ID set to LanguageInterface::LANGCODE_SITE_DEFAULT. + // Since this is not a real language, surround it by '***LANGUAGE_...***', + // like the negotiated languages below. $languages = $manager->getLanguages($flags); foreach ($languages as $id => $language) { - if ($id == 'site_default') { - $id = '***LANGUAGE_' . $id . '***'; + if ($id == LanguageInterface::LANGCODE_SITE_DEFAULT) { + $id = PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT; } $list[$id] = t($language->name); } @@ -448,7 +455,7 @@ public static function queryLanguageSubstitutions() { // Handle default language. $default = $manager->getDefaultLanguage()->id; - $changes['***LANGUAGE_site_default***'] = $default; + $changes[PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT] = $default; // Handle negotiated languages. $types = $manager->getDefinedLanguageTypesInfo(); diff --git a/core/modules/views/views.api.php b/core/modules/views/views.api.php index 5534df6..3f73e63 100644 --- a/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -6,6 +6,7 @@ */ use Drupal\Core\Language\LanguageInterface; +use Drupal\views\Plugin\views\PluginBase; /** * @defgroup views_overview Views overview @@ -579,7 +580,7 @@ function hook_views_query_substitutions(ViewExecutable $view) { '***CURRENT_VERSION***' => \Drupal::VERSION, '***CURRENT_TIME***' => REQUEST_TIME, '***LANGUAGE_language_content***' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id, - '***LANGUAGE_site_default***' => \Drupal::languageManager()->getDefaultLanguage()->id, + PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT => \Drupal::languageManager()->getDefaultLanguage()->id, ); }