You are here

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

Class

HideOnlyOneItemProcessor
Provides a processor that removes all results when the set has only 1 item.

Namespace

Drupal\facets\Plugin\facets\processor

Code

public function build(FacetInterface $facet, array $results) {
  if (count($results) !== 1) {
    return $results;
  }

  /** @var \Drupal\facets\Result\Result $result */
  $result = reset($results);
  return $result
    ->isActive() ? $results : [];
}