public function ShowSummaryProcessor::build in Facets 8
Alter the items in the summary before creating the renderable array.
Parameters
\Drupal\facets_summary\FacetsSummaryInterface $facet: The facet being changed.
array $build: The render array.
\Drupal\facets\FacetInterface[] $facets: The facets that are available.
Return value
array The render array.
Overrides BuildProcessorInterface::build
File
- modules/
facets_summary/ src/ Plugin/ facets_summary/ processor/ ShowSummaryProcessor.php, line 26
Class
- ShowSummaryProcessor
- Provides a processor that shows a summary of all selected facets.
Namespace
Drupal\facets_summary\Plugin\facets_summary\processorCode
public function build(FacetsSummaryInterface $facets_summary, array $build, array $facets) {
$facets_config = $facets_summary
->getFacets();
if (!isset($build['#items'])) {
return $build;
}
/** @var \Drupal\facets\Entity\Facet $facet */
foreach ($facets as $facet) {
if (empty($facet
->getActiveItems())) {
continue;
}
$items = $this
->getActiveDisplayValues($facet
->getResults());
$facet_summary = [
'#theme' => 'facets_summary_facet',
'#label' => $facets_config[$facet
->id()]['label'],
'#separator' => $facets_config[$facet
->id()]['separator'],
'#items' => $items,
'#facet_id' => $facet
->id(),
'#facet_admin_label' => $facet
->getName(),
];
array_unshift($build['#items'], $facet_summary);
}
return $build;
}