3 namespace Drupal\views\Plugin\views\filter;
5 use Drupal\Core\Language\LanguageInterface;
6 use Drupal\Core\Language\LanguageManagerInterface;
7 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8 use Drupal\views\Plugin\views\PluginBase;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Provides filtering by language.
14 * @ingroup views_filter_handlers
16 * @ViewsFilter("language")
18 class LanguageFilter extends InOperator implements ContainerFactoryPluginInterface {
21 * The language manager.
23 * @var \Drupal\Core\Language\LanguageManagerInterface
25 protected $languageManager;
28 * Constructs a new LanguageFilter instance.
30 * @param array $configuration
31 * A configuration array containing information about the plugin instance.
32 * @param string $plugin_id
33 * The plugin_id for the plugin instance.
34 * @param mixed $plugin_definition
35 * The plugin implementation definition.
36 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
37 * The language manager.
39 public function __construct($configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager) {
40 parent::__construct($configuration, $plugin_id, $plugin_definition);
42 $this->languageManager = $language_manager;
48 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
53 $container->get('language_manager')
60 public function getValueOptions() {
61 if (!isset($this->valueOptions)) {
62 $this->valueTitle = $this->t('Language');
63 // Pass the current values so options that are already selected do not get
64 // lost when there are changes in the language configuration.
65 $this->valueOptions = $this->listLanguages(LanguageInterface::STATE_ALL | LanguageInterface::STATE_SITE_DEFAULT | PluginBase::INCLUDE_NEGOTIATED, array_keys($this->value));
67 return $this->valueOptions;
73 public function query() {
74 // Don't filter by language in case the site is not multilingual, because
75 // there is no point in doing so.
76 if (!$this->languageManager->isMultilingual()) {