You are here

public function HideNonNarrowingResultProcessor::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/HideNonNarrowingResultProcessor.php, line 26

Class

HideNonNarrowingResultProcessor
Provides a processor that hides results that don't narrow results.

Namespace

Drupal\facets\Plugin\facets\processor

Code

public function build(FacetInterface $facet, array $results) {
  $facet_results = $facet
    ->getResults();
  $result_count = 0;
  foreach ($facet_results as $result) {
    if ($result
      ->isActive()) {
      $result_count += $result
        ->getCount();
    }
  }

  /** @var \Drupal\facets\Result\ResultInterface $result */
  foreach ($results as $id => $result) {
    if (($result
      ->getCount() == $result_count || $result
      ->getCount() == 0) && !$result
      ->isActive()) {
      unset($results[$id]);
    }
  }
  return $results;
}