You are here

function filter_harmonizer_is_empty in Views Filter Harmonizer 1.0.x

Same name and namespace in other branches
  1. 8 filter_harmonizer.module \filter_harmonizer_is_empty()

Returns TRUE when the supplied regular filter info is empty or incomplete.

By default filter $value is considered empty when it: -- equals NULL or the empty string '' or an empty array, or -- when all of its array elements

  • equal NULL or '' or an empty array, or
  • are arrays with elements that equal NULL or '' or an empty array

Parameters

FilterPluginBase $filter: Contains the (limit) value and operator.

1 call to filter_harmonizer_is_empty()
filter_harmonizer_stringify_regular_filter in ./filter_harmonizer.module
Takes a regular filter and outputs its filter value(s) as a string for later use as a contextual argument in the browser URL. For example a GeofieldProximityFilter value may return "-37.8,144.9<=100km".

File

./filter_harmonizer.module, line 159
filter_harmonizer.module

Code

function filter_harmonizer_is_empty(FilterPluginBase $filter) {
  if (!$filter || !isset($filter->value)) {
    return TRUE;
  }

  // This covers most simple regular filters...
  $is_empty = $filter->value == '' || $filter->value === [] || empty($filter->no_operator) && empty($filter->operator);

  // And here's for the more complex ones, e.g. multi-valued ones.
  if (!$is_empty && is_array($filter->value)) {
    foreach ($filter->value as $key => $val) {
      if ($is_empty = !isset($val) || $val === [] || $val == '') {
        break;
      }
    }
  }

  // Let other modules modify the meaning of $is_empty before we return it.
  // Example: Geofield Proximity filter.
  Drupal::moduleHandler()
    ->invokeAll('filter_harmonizer_is_empty', [
    &$is_empty,
    $filter,
  ]);
  return $is_empty;
}