function FilterPluginBase::storeExposedInput
Same name in other branches
- 9 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::storeExposedInput()
- 8.9.x core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::storeExposedInput()
- 11.x core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::storeExposedInput()
Overrides HandlerBase::storeExposedInput
File
-
core/
modules/ views/ src/ Plugin/ views/ filter/ FilterPluginBase.php, line 1549
Class
- FilterPluginBase
- Base class for Views filters handler plugins.
Namespace
Drupal\views\Plugin\views\filterCode
public function storeExposedInput($input, $status) {
if (empty($this->options['exposed']) || empty($this->options['expose']['identifier'])) {
return TRUE;
}
if (empty($this->options['expose']['remember'])) {
return;
}
// Check if we store exposed value for current user.
$user = \Drupal::currentUser();
$allowed_rids = empty($this->options['expose']['remember_roles']) ? [] : array_filter($this->options['expose']['remember_roles']);
$intersect_rids = array_intersect(array_keys($allowed_rids), $user->getRoles());
if (empty($intersect_rids)) {
return;
}
// Figure out which display id is responsible for the filters, so we
// know where to look for session stored values.
$display_id = $this->view->display_handler
->isDefaulted('filters') ? 'default' : $this->view->current_display;
// Shortcut test.
$operator = !empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']);
// False means that we got a setting that means to recurse ourselves,
// so we should erase whatever happened to be there.
$session = $this->view
->getRequest()
->getSession();
$views_session = $session->get('views', []);
if (!$status && isset($views_session[$this->view->storage
->id()][$display_id])) {
$session_ref =& $views_session[$this->view->storage
->id()][$display_id];
if ($operator && isset($session_ref[$this->options['expose']['operator_id']])) {
unset($session_ref[$this->options['expose']['operator_id']]);
}
if (isset($session_ref[$this->options['expose']['identifier']])) {
unset($session_ref[$this->options['expose']['identifier']]);
}
}
if ($status) {
if (!isset($views_session[$this->view->storage
->id()][$display_id])) {
$views_session[$this->view->storage
->id()][$display_id] = [];
}
$session_ref =& $views_session[$this->view->storage
->id()][$display_id];
if ($operator && isset($input[$this->options['expose']['operator_id']])) {
$session_ref[$this->options['expose']['operator_id']] = $input[$this->options['expose']['operator_id']];
}
$session_ref[$this->options['expose']['identifier']] = $input[$this->options['expose']['identifier']];
}
if (!empty($views_session)) {
$session->set('views', $views_session);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.