public function GlossaryAZAllItemsProcessor::build in Search API AZ Glossary 8
Same name and namespace in other branches
- 8.4 src/Plugin/facets/processor/GlossaryAZAllItemsProcessor.php \Drupal\search_api_glossary\Plugin\facets\processor\GlossaryAZAllItemsProcessor::build()
- 8.2 src/Plugin/facets/processor/GlossaryAZAllItemsProcessor.php \Drupal\search_api_glossary\Plugin\facets\processor\GlossaryAZAllItemsProcessor::build()
- 8.3 src/Plugin/facets/processor/GlossaryAZAllItemsProcessor.php \Drupal\search_api_glossary\Plugin\facets\processor\GlossaryAZAllItemsProcessor::build()
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/ GlossaryAZAllItemsProcessor.php, line 28
Class
- GlossaryAZAllItemsProcessor
- Provides a processor to rewrite facet results to pad out missing alpha.
Namespace
Drupal\search_api_glossary\Plugin\facets\processorCode
public function build(FacetInterface $facet, array $results) {
$show_all_item = new Result(t('All')
->getUntranslatedString(), t('All'), count($results));
// Process the results count.
$show_all_item_count = 0;
foreach ($results as $result) {
$show_all_item_count += $result
->getCount();
}
// Set the total results.
$show_all_item
->setCount($show_all_item_count);
// Deal with the ALL Items path.
$link = $facet
->getFacetSource()
->getPath();
// Set the path.
$link
->setAbsolute();
$show_all_item
->setUrl($link);
// If no other facets are selected, default to ALL.
if (empty($facet
->getActiveItems())) {
$show_all_item
->setActiveState(TRUE);
}
// All done.
$results[] = $show_all_item;
return $results;
}