diff --git a/src/FacetManager/DefaultFacetManager.php b/src/FacetManager/DefaultFacetManager.php index a4468d7..cb6da77 100644 --- a/src/FacetManager/DefaultFacetManager.php +++ b/src/FacetManager/DefaultFacetManager.php @@ -9,6 +9,7 @@ use Drupal\facets\Exception\InvalidProcessorException; use Drupal\facets\FacetInterface; use Drupal\facets\FacetSource\FacetSourcePluginManager; use Drupal\facets\Processor\BuildProcessorInterface; +use Drupal\facets\Processor\PostQueryProcessorInterface; use Drupal\facets\Processor\PreQueryProcessorInterface; use Drupal\facets\Processor\ProcessorInterface; use Drupal\facets\Processor\ProcessorPluginManager; @@ -204,6 +205,18 @@ class DefaultFacetManager { $this->processedFacetSources[$facetsource_id] = TRUE; } + + foreach ($this->facets as $facet) { + foreach ($facet->getProcessorsByStage(ProcessorInterface::STAGE_POST_QUERY) as $processor) { + /** @var \Drupal\facets\processor\PostQueryProcessorInterface $post_query_processor */ + $post_query_processor = $this->processorPluginManager->createInstance($processor->getPluginDefinition()['id'], ['facet' => $facet]); + if (!$post_query_processor instanceof PostQueryProcessorInterface) { + throw new InvalidProcessorException(new FormattableMarkup("The processor @processor has a post_query definition but doesn't implement the required PostQueryProcessor interface", ['@processor' => $processor->getPluginDefinition()['id']])); + } + $post_query_processor->postQuery($facet); + } + } + } /** @@ -216,7 +229,6 @@ class DefaultFacetManager { if (empty($this->facets)) { $this->facets = $this->getEnabledFacets(); foreach ($this->facets as $facet) { - foreach ($facet->getProcessorsByStage(ProcessorInterface::STAGE_PRE_QUERY) as $processor) { /** @var PreQueryProcessorInterface $pre_query_processor */ $pre_query_processor = $this->processorPluginManager->createInstance($processor->getPluginDefinition()['id'], ['facet' => $facet]); @@ -283,7 +295,7 @@ class DefaultFacetManager { /** @var \Drupal\facets\Processor\BuildProcessorInterface $build_processor */ $build_processor = $this->processorPluginManager->createInstance($processor->getPluginDefinition()['id'], ['facet' => $facet]); if (!$build_processor instanceof BuildProcessorInterface) { - throw new InvalidProcessorException(new FormattableMarkup("The processor @processor has a build definition but doesn't implement the required BuildProcessorInterface interface", ['@processor' => $processor['processor_id']])); + throw new InvalidProcessorException(new FormattableMarkup("The processor @processor has a build definition but doesn't implement the required BuildProcessorInterface interface", ['@processor' => $processor->getPluginDefinition()['id']])); } $results = $build_processor->build($facet, $results); } diff --git a/src/Processor/PostQueryProcessorInterface.php b/src/Processor/PostQueryProcessorInterface.php index 967af9b..0b925ff 100644 --- a/src/Processor/PostQueryProcessorInterface.php +++ b/src/Processor/PostQueryProcessorInterface.php @@ -2,6 +2,7 @@ namespace Drupal\facets\Processor; +use Drupal\facets\FacetInterface; /** * Processor runs after the query was executed. @@ -12,11 +13,12 @@ interface PostQueryProcessorInterface extends ProcessorInterface { * Runs after the query was executed. * * Uses the query results and can alter those results, for example a - * ValueCallbackProcessor. + * ValueCallbackProcessor. If results are being changed, this processor should + * handle saving itself. * - * @param \Drupal\facets\Result\Result[] $results - * The results being changed. + * @param \Drupal\facets\FacetInterface $facet + * The facet that's being changed. */ - public function postQuery(array $results); + public function postQuery(FacetInterface $facet); } diff --git a/src/Processor/ProcessorInterface.php b/src/Processor/ProcessorInterface.php index 6b1c4b5..2429841 100644 --- a/src/Processor/ProcessorInterface.php +++ b/src/Processor/ProcessorInterface.php @@ -20,7 +20,7 @@ interface ProcessorInterface extends ConfigurablePluginInterface, PluginInspecti /** * Processing stage: post_query. */ - const STAGE_POST_QUERY = 'post query'; + const STAGE_POST_QUERY = 'post_query'; /** * Processing stage: build.