function filter_harmonizer_formalize_contextual_arg in Views Filter Harmonizer 8
Same name and namespace in other branches
- 1.0.x filter_harmonizer.module \filter_harmonizer_formalize_contextual_arg()
Takes a contextual filter arg and outputs it as form value(s) to later populate the exposed form belonging to a companion regular filter.
Parameters
FilterPluginBase $regular_filter: The regular filter handler whose (exposed) form will be populated from the contextual filter.
ArgumentPluginBase $contextual_filter: The contextual filter whose arg will be used to return regular filter form values.
Return value
string|array A single number or string or array of values to populate the regular filter
1 call to filter_harmonizer_formalize_contextual_arg()
- filter_harmonizer_harmonize_and_record_filter_pairs in ./
filter_harmonizer.module - When a View on a page is first loaded and if a context filter is present, we obey any associated /arg1/arg2/.. on the browser URL/address bar. Then, if regular exposed filters are present too for fields by the same names, and their form values are…
File
- ./
filter_harmonizer.module, line 227 - filter_harmonizer.module
Code
function filter_harmonizer_formalize_contextual_arg(FilterPluginBase $regular_filter, ArgumentPluginBase $contextual_filter) {
$values = Drupal::moduleHandler()
->invokeAll('filter_harmonizer_formalize_contextual_arg', [
$contextual_filter,
$regular_filter,
]);
if (empty($values)) {
// If no special implementation has provided the contextual argument in
// a format we can use on the regular filter form, then use
// $contextual_filter_argument as is.
if ($contextual_filter->argument !== $contextual_filter->options['exception']['value']) {
$values = [];
$and_ed = explode(',', $contextual_filter->argument);
foreach ($and_ed as $value) {
$or_ed = explode('+', $value);
// If '+' doesn't work, try space instead. This is how '+' usually gets
// converted into $contextual_filter->argument.
if (count($or_ed) == 1) {
$or_ed = explode(' ', $value);
}
$values = array_merge($values, $or_ed);
}
}
}
// If the contextual multiplicity is at odds with the regular filter, make
// an attempt to sort out the mismatch.
$is_multi_valued = !empty($regular_filter->options['expose']['multiple']);
if ($is_multi_valued) {
if (!is_array($values)) {
// Convert the single value into an array (ie. a multi-value).
$values = [
$values,
];
}
}
return $values;
}