AllowedLanguages.php in Allowed Languages 8
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() {
$user = allowed_languages_get_current_user();
$allowed_languages = allowed_languages_get_allowed_languages_for_user($user);
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;
}
}