diff --git a/src/FacetManager/DefaultFacetManager.php b/src/FacetManager/DefaultFacetManager.php index 41105a1..50b3bf2 100644 --- a/src/FacetManager/DefaultFacetManager.php +++ b/src/FacetManager/DefaultFacetManager.php @@ -287,29 +287,23 @@ class DefaultFacetManager { // @see \Drupal\facets\Processor\WidgetOrderProcessorInterface. $results = $facet->getResults(); - $active_sorts = []; - foreach ($facet->getProcessorsByStage(ProcessorInterface::STAGE_BUILD) as $processor) { - /** @var \Drupal\facets\Processor\BuildProcessorInterface $build_processor */ - $build_processor = $this->processorPluginManager->createInstance($processor->getPluginDefinition()['id'], ['facet' => $facet]); - if (!$build_processor instanceof BuildProcessorInterface) { + if (!$processor instanceof BuildProcessorInterface) { throw new InvalidProcessorException("The processor {$processor->getPluginDefinition()['id']} has a build definition but doesn't implement the required BuildProcessorInterface interface"); } - $results = $build_processor->build($facet, $results); + $results = $processor->build($facet, $results); } - // Load all processors, because getProcessorsByStage does not return the - // correct configuration for the processors. - // @todo: Fix when https://www.drupal.org/node/2722267 is fixed. - $processors = $facet->getProcessors(); + // Trigger sort stage. + $active_sort_processors = []; foreach ($facet->getProcessorsByStage(ProcessorInterface::STAGE_SORT) as $processor) { - $active_sorts[] = $processors[$processor->getPluginId()]; + $active_sort_processors[] = $processor; } - uasort($results, function ($a, $b) use ($active_sorts) { + uasort($results, function ($a, $b) use ($active_sort_processors) { $return = 0; - foreach ($active_sorts as $sort) { - if ($return = $sort->sortResults($a, $b)) { - if ($sort->getConfiguration()['sort'] == 'DESC') { + foreach ($active_sort_processors as $sort_processor) { + if ($return = $sort_processor->sortResults($a, $b)) { + if ($sort_processor->getConfiguration()['sort'] == 'DESC') { $return *= -1; } break;