You are here

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

Class

ShowSiblingsProcessor
Provides a processor that only shows deepest level items.

Namespace

Drupal\facets\Plugin\facets\processor

Code

public function build(FacetInterface $facet, array $results) {

  /** @var \Drupal\facets\Result\ResultInterface[] $results */
  if ($facet
    ->getUseHierarchy()) {
    $rawValues = array_map(function ($result) {
      return $result
        ->getRawValue();
    }, $results);
    foreach ($facet
      ->getHierarchyInstance()
      ->getSiblingIds($rawValues, $facet
      ->getActiveItems()) as $siblingId) {
      $results[] = new Result($facet, $siblingId, $siblingId, 0);
    }
  }
  return $results;
}