protected function EntityReferenceFilterViewResult::getFilterArgs in Views Reference Filter 8
Get the calculated filter arguments.
Return value
array Calculated arguments.
1 call to EntityReferenceFilterViewResult::getFilterArgs()
- EntityReferenceFilterViewResult::getConfiguredViewsOptions in src/
Plugin/ views/ filter/ EntityReferenceFilterViewResult.php - Returns options for the selected filter.
File
- src/
Plugin/ views/ filter/ EntityReferenceFilterViewResult.php, line 245
Class
- EntityReferenceFilterViewResult
- Filter by entity id using items got from the another view..
Namespace
Drupal\entityreference_filter\Plugin\views\filterCode
protected function getFilterArgs() {
$args = [];
$filters_by_identifier = [];
$view_args = $this
->getViewArgs();
$view_context_args = $this
->getViewContextArgs();
$reference_arguments = $this->options['reference_arguments'] ?? NULL;
if (isset($reference_arguments)) {
$arg_str = trim($reference_arguments);
if ($arg_str !== '') {
$args = explode('/', $arg_str);
foreach ($args as $i => $arg) {
$arg = trim($arg);
$first_char = mb_substr($arg, 0, 1);
// URL argument.
if ($first_char === '!') {
$arg_no = (int) mb_substr($arg, 1) - 1;
if ($arg_no >= 0) {
$args[$i] = $view_args[$arg_no] ?? NULL;
}
}
// Exposed filter as argument.
if ($first_char === '[' && mb_substr($arg, -1) === ']') {
// Collect exposed filters.
if (empty($filters_by_identifier) && !empty($this->view->filter)) {
foreach ($this->view->filter as $filter_handler) {
if (!$filter_handler
->isExposed()) {
continue;
}
$filters_by_identifier[$filter_handler->options['expose']['identifier']] = $filter_handler;
}
}
$args[$i] = NULL;
$filter_name = mb_substr($arg, 1, -1);
// User input.
$input = $this->view
->getExposedInput();
if (isset($input[$filter_name])) {
$args[$i] = $input[$filter_name];
}
elseif (isset($filters_by_identifier[$filter_name])) {
$args[$i] = $filters_by_identifier[$filter_name]->value;
}
// Glue multiple values.
if (is_array($args[$i]) && !empty($args[$i])) {
$args[$i] = implode('+', $args[$i]);
}
}
// Contextual filter as argument.
if ($first_char === '#' && !empty($view_context_args)) {
$arg_no = (int) mb_substr($arg, 1) - 1;
$args[$i] = $view_context_args[$arg_no] ?? NULL;
}
// Overwrite empty values to NULL.
if ($args[$i] === 'All' || $args[$i] === []) {
$args[$i] = NULL;
}
}
}
}
return $args;
}