You are here

protected function FilterPluginBase::hasValidGroupedValue in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::hasValidGroupedValue()

Determines if the given grouped filter entry has a valid value.

Parameters

array $group: A group entry as defined by buildGroupForm().

Return value

bool

1 call to FilterPluginBase::hasValidGroupedValue()
FilterPluginBase::buildGroupValidate in core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Validate the build group options form.
1 method overrides FilterPluginBase::hasValidGroupedValue()
Date::hasValidGroupedValue in core/modules/views/src/Plugin/views/filter/Date.php
Determines if the given grouped filter entry has a valid value.

File

core/modules/views/src/Plugin/views/filter/FilterPluginBase.php, line 686

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function hasValidGroupedValue(array $group) {
  $operators = $this
    ->operators();
  if ($operators[$group['operator']]['values'] == 0) {

    // Some filters, such as "is empty," do not require a value to be
    // specified in order to be valid entries.
    return TRUE;
  }
  else {
    if (is_string($group['value'])) {
      return trim($group['value']) != '';
    }
    elseif (is_array($group['value'])) {

      // Some filters allow multiple options to be selected (for example, node
      // types). Ensure at least the minimum number of values is present for
      // this entry to be considered valid.
      $min_values = $operators[$group['operator']]['values'];
      $actual_values = count(array_filter($group['value'], 'static::arrayFilterZero'));
      return $actual_values >= $min_values;
    }
  }
  return FALSE;
}