diff --git a/core/modules/language/src/Element/LanguageConfiguration.php b/core/modules/language/src/Element/LanguageConfiguration.php index aa6f94b..82c6f8f 100644 --- a/core/modules/language/src/Element/LanguageConfiguration.php +++ b/core/modules/language/src/Element/LanguageConfiguration.php @@ -97,7 +97,7 @@ public static function processLanguageConfiguration(&$element, FormStateInterfac protected static function getDefaultOptions() { $language_options = array( LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (!language)", array('!language' => static::languageManager()->getDefaultLanguage()->getName())), - 'current_interface' => t('Current interface language'), + 'current_interface' => t('!type language selected for page', array('!type' => t('User interface text'))), 'authors_default' => t("Author's preferred language"), ); diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index 9c0f49b..e648cb6 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -507,14 +507,17 @@ public function getProvider() { * - \Drupal\views\Plugin\views\PluginBase::INCLUDE_ENTITY: Add * entity row language types. Note that these are only supported for * display options, not substituted in queries. + * @param array|null $current_values + * The list of current values if available. * * @return array * An array of language names, keyed by the language code. Negotiated and * special languages have special codes that are substituted in queries by * PluginBase::queryLanguageSubstitutions(). */ - protected function listLanguages($flags = LanguageInterface::STATE_ALL) { + protected function listLanguages($flags = LanguageInterface::STATE_ALL, array $current_values = NULL) { $manager = \Drupal::languageManager(); + $languages = $manager->getLanguages($flags); $list = array(); // The entity languages should come first, if requested. @@ -523,32 +526,46 @@ protected function listLanguages($flags = LanguageInterface::STATE_ALL) { $list['***LANGUAGE_entity_default***'] = $this->t('Original language of content in view row'); } - // The Language Manager class takes care of the STATE_SITE_DEFAULT case. - // It comes in with ID set to LanguageInterface::LANGCODE_SITE_DEFAULT. + // STATE_SITE_DEFAULT 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 == LanguageInterface::LANGCODE_SITE_DEFAULT) { - $id = PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT; - } - $list[$id] = $this->t($language->getName()); + if ($flags & LanguageInterface::STATE_SITE_DEFAULT) { + $list[PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT] = $this->t($languages[LanguageInterface::LANGCODE_SITE_DEFAULT]->getName()); + // Remove site's default from the languages' array so it's not added + // with the real languages below. + unset($languages[LanguageInterface::LANGCODE_SITE_DEFAULT]); } // Add in negotiated languages, if requested. if ($flags & PluginBase::INCLUDE_NEGOTIATED) { - $types = $manager->getDefinedLanguageTypesInfo(); - foreach ($types as $id => $type) { - // Omit unnamed types. These are things like language_url, which are - // not configurable and do not need to be in this list. And surround - // IDs by '***LANGUAGE_...***', to avoid query collisions. - if (isset($type['name'])) { + $types_info = $manager->getDefinedLanguageTypesInfo(); + $types = $manager->getLanguageTypes(); + foreach ($types as $id) { + if (isset($types_info[$id]['name'])) { + $name = $types_info[$id]['name']; + // Surround IDs by '***LANGUAGE_...***', to avoid query collisions. + $id = '***LANGUAGE_' . $id . '***'; + $list[$id] = $this->t('!type language selected for page', array('!type' => $name)); + } + } + if (!empty($current_values)) { + foreach ($types_info as $id => $type) { $id = '***LANGUAGE_' . $id . '***'; - $list[$id] = $this->t('!type language selected for page', array('!type' => $type['name'])); + // If this (non-configurable) type is among the current values, + // add that option too, so it is not lost. If not among the current + // values, skip displaying it to avoid user confusion. + if (isset($type['name']) && !isset($list[$id]) && in_array($id, $current_values)) { + $list[$id] = $this->t('!type language selected for page', array('!type' => $type['name'])); + } } } } + // Add real languages. + foreach ($languages as $id => $language) { + $list[$id] = $this->t($language->getName()); + } + return $list; } diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 290d1a7..6fa762e 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -2609,6 +2609,7 @@ public function getExtenders() { */ protected function buildRenderingLanguageOptions() { // @todo Consider making these plugins. See https://drupal.org/node/2173811. + // @todo pass over the current selected options. return $this->listLanguages(LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_SITE_DEFAULT | PluginBase::INCLUDE_NEGOTIATED | PluginBase::INCLUDE_ENTITY); } diff --git a/core/modules/views/src/Plugin/views/filter/LanguageFilter.php b/core/modules/views/src/Plugin/views/filter/LanguageFilter.php index 9826998..26e3f1c 100644 --- a/core/modules/views/src/Plugin/views/filter/LanguageFilter.php +++ b/core/modules/views/src/Plugin/views/filter/LanguageFilter.php @@ -65,6 +65,7 @@ public static function create(ContainerInterface $container, array $configuratio public function getValueOptions() { if (!isset($this->valueOptions)) { $this->valueTitle = $this->t('Language'); + // @todo pass over the current selected options. $this->valueOptions = $this->listLanguages(LanguageInterface::STATE_ALL |LanguageInterface::STATE_SITE_DEFAULT | PluginBase::INCLUDE_NEGOTIATED); } }