Commit 5a520050 authored by alexpott's avatar alexpott

Issue #2328573 by el7cosmos, jhodgdon, YesCT: 'site_default' needs to be a language constant.

parent 9315a45e
......@@ -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) {
......
......@@ -51,6 +51,11 @@ interface LanguageInterface {
*/
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.
*/
......
......@@ -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) {
......
......@@ -232,7 +232,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;
}
......@@ -294,13 +294,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;
......
......@@ -93,7 +93,7 @@ public static function processLanguageConfiguration(&$element, FormStateInterfac
*/
protected static function getDefaultOptions() {
$language_options = array(
'site_default' => t("Site's default language (!language)", array('!language' => static::languageManager()->getDefaultLanguage()->name)),
LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (!language)", array('!language' => static::languageManager()->getDefaultLanguage()->name)),
'current_interface' => t('Current interface language'),
'authors_default' => t("Author's preferred language"),
);
......
......@@ -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;
......
......@@ -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');
......
......@@ -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.
......
......@@ -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');
......
......@@ -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'));
......
......@@ -51,6 +51,13 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
*/
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.
*
......@@ -409,13 +416,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] = $this->t($language->name);
}
......@@ -455,7 +462,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();
......
......@@ -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,
);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment