Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / views / src / Plugin / views / filter / LanguageFilter.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\filter;
4
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;
10
11 /**
12  * Provides filtering by language.
13  *
14  * @ingroup views_filter_handlers
15  *
16  * @ViewsFilter("language")
17  */
18 class LanguageFilter extends InOperator implements ContainerFactoryPluginInterface {
19
20   /**
21    * The language manager.
22    *
23    * @var \Drupal\Core\Language\LanguageManagerInterface
24    */
25   protected $languageManager;
26
27   /**
28    * Constructs a new LanguageFilter instance.
29    *
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.
38    */
39   public function __construct($configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager) {
40     parent::__construct($configuration, $plugin_id, $plugin_definition);
41
42     $this->languageManager = $language_manager;
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
49     return new static(
50       $configuration,
51       $plugin_id,
52       $plugin_definition,
53       $container->get('language_manager')
54     );
55   }
56
57   /**
58    * {@inheritdoc}
59    */
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));
66     }
67     return $this->valueOptions;
68   }
69
70   /**
71    * {@inheritdoc}
72    */
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()) {
77       return;
78     }
79
80     parent::query();
81   }
82
83 }