You are here

protected function DefaultFacetsSummaryManager::buildResultTree in Facets 8

Build result tree, taking possible children into account.

Parameters

bool $show_count: Show the count next to the facet.

\Drupal\facets\Result\ResultInterface[] $results: Facet results array.

Return value

array The rendered links to the active facets.

1 call to DefaultFacetsSummaryManager::buildResultTree()
DefaultFacetsSummaryManager::build in modules/facets_summary/src/FacetsSummaryManager/DefaultFacetsSummaryManager.php
Builds a facet and returns it as a renderable array.

File

modules/facets_summary/src/FacetsSummaryManager/DefaultFacetsSummaryManager.php, line 154

Class

DefaultFacetsSummaryManager
The facet summary manager.

Namespace

Drupal\facets_summary\FacetsSummaryManager

Code

protected function buildResultTree($show_count, array $results) {
  $items = [];
  foreach ($results as $result) {
    if ($result
      ->isActive()) {
      $item = [
        '#theme' => 'facets_result_item__summary',
        '#value' => $result
          ->getDisplayValue(),
        '#show_count' => $show_count,
        '#count' => $result
          ->getCount(),
        '#is_active' => TRUE,
        '#facet' => $result
          ->getFacet(),
        '#raw_value' => $result
          ->getRawValue(),
      ];
      $item = (new Link($item, $result
        ->getUrl()))
        ->toRenderable();
      $item['#wrapper_attributes'] = [
        'class' => [
          'facet-summary-item--facet',
        ],
      ];
      $items[] = $item;
    }
    if ($children = $result
      ->getChildren()) {
      $items = array_merge($items, $this
        ->buildResultTree($show_count, $children));
    }
  }
  return $items;
}