diff --git a/core/modules/language/tests/src/Kernel/Views/FilterLanguageTest.php b/core/modules/language/tests/src/Kernel/Views/FilterLanguageTest.php index 17764f64dd..3a8f1b28e3 100644 --- a/core/modules/language/tests/src/Kernel/Views/FilterLanguageTest.php +++ b/core/modules/language/tests/src/Kernel/Views/FilterLanguageTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\language\Kernel\Views; +use Drupal\Core\Language\LanguageInterface; use Drupal\views\Views; /** @@ -55,4 +56,43 @@ public function testFilter() { } } + /** + * Tests the language filter value options. + */ + public function testValueOptions() { + $view = Views::getView('test_view'); + $view->setDisplay(); + $view->displayHandlers->get('default')->overrideOption('filters', [ + 'langcode' => [ + 'id' => 'langcode', + 'table' => 'views_test_data', + 'field' => 'langcode', + 'value' => [], + ], + ]); + $this->executeView($view); + $this->assertSame([ + '***LANGUAGE_' . LanguageInterface::LANGCODE_SITE_DEFAULT . '***', + '***LANGUAGE_' . LanguageInterface::TYPE_INTERFACE . '***', + 'en', + 'xx-lolspeak', + LanguageInterface::LANGCODE_NOT_SPECIFIED, + LanguageInterface::LANGCODE_NOT_APPLICABLE, + ], array_keys($view->filter['langcode']->getValueOptions())); + $view->destroy(); + + $view->setDisplay(); + $view->displayHandlers->get('default')->overrideOption('filters', [ + 'langcode' => [ + 'id' => 'langcode', + 'table' => 'views_test_data', + 'field' => 'langcode', + 'value' => [], + 'exposed' => TRUE, + ], + ]); + $this->executeView($view); + $this->assertSame(['en', 'xx-lolspeak'], array_keys($view->filter['langcode']->getValueOptions())); + } + } diff --git a/core/modules/views/src/Plugin/views/filter/LanguageFilter.php b/core/modules/views/src/Plugin/views/filter/LanguageFilter.php index 69fdc81a1f..dc4d4d2872 100644 --- a/core/modules/views/src/Plugin/views/filter/LanguageFilter.php +++ b/core/modules/views/src/Plugin/views/filter/LanguageFilter.php @@ -2,6 +2,7 @@ namespace Drupal\views\Plugin\views\filter; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -60,9 +61,11 @@ public static function create(ContainerInterface $container, array $configuratio public function getValueOptions() { if (!isset($this->valueOptions)) { $this->valueTitle = $this->t('Language'); + // Only configurable languages are displayed when filter is exposed. + $languages_to_list = $this->options['exposed'] ? LanguageInterface::STATE_CONFIGURABLE : LanguageInterface::STATE_ALL | LanguageInterface::STATE_SITE_DEFAULT | PluginBase::INCLUDE_NEGOTIATED; // Pass the current values so options that are already selected do not get // lost when there are changes in the language configuration. - $this->valueOptions = $this->listLanguages(LanguageInterface::STATE_ALL | LanguageInterface::STATE_SITE_DEFAULT | PluginBase::INCLUDE_NEGOTIATED, array_keys($this->value)); + $this->valueOptions = $this->listLanguages($languages_to_list, array_keys($this->value)); } return $this->valueOptions; }