HideNonNarrowingResultProcessor.php in Facets 8
File
src/Plugin/facets/processor/HideNonNarrowingResultProcessor.php
View source
<?php
namespace Drupal\facets\Plugin\facets\processor;
use Drupal\facets\FacetInterface;
use Drupal\facets\Processor\BuildProcessorInterface;
use Drupal\facets\Processor\ProcessorPluginBase;
class HideNonNarrowingResultProcessor extends ProcessorPluginBase implements BuildProcessorInterface {
public function build(FacetInterface $facet, array $results) {
$facet_results = $facet
->getResults();
$result_count = 0;
foreach ($facet_results as $result) {
if ($result
->isActive()) {
$result_count += $result
->getCount();
}
}
foreach ($results as $id => $result) {
if (($result
->getCount() == $result_count || $result
->getCount() == 0) && !$result
->isActive()) {
unset($results[$id]);
}
}
return $results;
}
}