You are here

protected function DataProviderVariable::applyFilters in RESTful 7.2

Removes plugins from the list based on the request options.

Parameters

\Drupal\restful\Plugin\resource\ResourceInterface[] $variables: The array of resource plugins keyed by instance ID.

Return value

\Drupal\restful\Plugin\resource\ResourceInterface[] The same array minus the filtered plugins.

Throws

\Drupal\restful\Exception\BadRequestException

\Drupal\restful\Exception\ServiceUnavailableException

1 call to DataProviderVariable::applyFilters()
DataProviderVariable::getIndexIds in modules/restful_example/src/Plugin/resource/variables/DataProviderVariable.php
Returns the ID to render for the current index GET request.

File

modules/restful_example/src/Plugin/resource/variables/DataProviderVariable.php, line 168
Contains \Drupal\restful_example\Plugin\resource\variables\DataProviderVariable.

Class

DataProviderVariable
Class DataProviderVariable.

Namespace

Drupal\restful_example\Plugin\resource\variables

Code

protected function applyFilters(array $variables) {
  $filters = $this
    ->parseRequestForListFilter();

  // Apply the filter to the list of plugins.
  foreach ($variables as $delta => $variable) {
    $variable_name = $variable['name'];

    // A filter on a result needs the ResourceFieldCollection representing the
    // result to return.
    $interpreter = $this
      ->initDataInterpreter($variable_name);
    $this->fieldDefinitions
      ->setInterpreter($interpreter);
    foreach ($filters as $filter) {
      if (!$this->fieldDefinitions
        ->evalFilter($filter)) {
        unset($variables[$delta]);
      }
    }
  }
  $this->fieldDefinitions
    ->setInterpreter(NULL);
  return $variables;
}