AllowedLanguages.php in Allowed Languages 2.x
File
src/Plugin/views/filter/AllowedLanguages.php
View source
<?php
namespace Drupal\allowed_languages\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
class AllowedLanguages extends FilterPluginBase {
public function adminSummary() {
return $this
->t('Current users allowed languages');
}
public function canExpose() {
return FALSE;
}
public function query() {
$allowed_languages = \Drupal::service('allowed_languages.allowed_languages_manager')
->assignedLanguages();
if ($allowed_languages) {
$this
->ensureMyTable();
$field = "{$this->tableAlias}.{$this->realField}";
$value = array_values($allowed_languages);
$this->query
->addWhere($this->options['group'], $field, $value, 'IN');
}
}
public function getCacheContexts() {
$contexts = parent::getCacheContexts();
$contexts[] = 'user';
return $contexts;
}
}