public function ResourceFieldCollection::evalFilter in RESTful 7.2
Evaluate a parsed filter on a field collection.
Parameters
array $filter: The parsed filter.
Return value
bool TRUE if the collection matches the filter. FALSE otherwise.
Overrides ResourceFieldCollectionInterface::evalFilter
File
- src/
Plugin/ resource/ Field/ ResourceFieldCollection.php, line 277 - Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldCollection.
Class
Namespace
Drupal\restful\Plugin\resource\FieldCode
public function evalFilter(array $filter) {
// Initialize to TRUE for AND and FALSE for OR (neutral value).
$match = $filter['conjunction'] == 'AND';
for ($index = 0; $index < count($filter['value']); $index++) {
if (!($resource_field = $this
->get($filter['public_field']))) {
// If the field is unknown don't use se filter.
return TRUE;
}
$filter_value = $resource_field
->value($this
->getInterpreter());
if (is_null($filter_value)) {
// Property doesn't exist on the plugin, so filter it out.
return FALSE;
}
if ($filter['conjunction'] == 'OR') {
$match = $match || $this::evaluateExpression($filter_value, $filter['value'][$index], $filter['operator'][$index]);
if ($match) {
break;
}
}
else {
$match = $match && $this::evaluateExpression($filter_value, $filter['value'][$index], $filter['operator'][$index]);
if (!$match) {
break;
}
}
}
return $match;
}