You are here

public function CountLimitProcessor::build in Facets 8

Runs before the renderable array is created.

Parameters

\Drupal\facets\FacetInterface $facet: The facet being changed.

\Drupal\facets\Result\ResultInterface[] $results: The results being changed.

Return value

\Drupal\facets\Result\ResultInterface[] The changed results.

Overrides BuildProcessorInterface::build

File

src/Plugin/facets/processor/CountLimitProcessor.php, line 27

Class

CountLimitProcessor
Provides a count limit processor.

Namespace

Drupal\facets\Plugin\facets\processor

Code

public function build(FacetInterface $facet, array $results) {
  $config = $this
    ->getConfiguration();
  $min_count = $config['minimum_items'];
  $max_count = $config['maximum_items'];

  /** @var \Drupal\facets\Result\Result $result */
  foreach ($results as $id => $result) {
    if ($min_count && $result
      ->getCount() < $min_count || $max_count && $result
      ->getCount() > $max_count) {
      unset($results[$id]);
    }
  }
  return $results;
}