diff --git a/src/FacetManager/FacetManagerPluginBase.php b/src/FacetManager/FacetManagerPluginBase.php index 41e1f68..77c37e1 100644 --- a/src/FacetManager/FacetManagerPluginBase.php +++ b/src/FacetManager/FacetManagerPluginBase.php @@ -121,6 +121,12 @@ abstract class FacetManagerPluginBase extends PluginBase implements FacetManager protected $searcher_id; /** + * Stop all the rendering + * @var bool + */ + protected $abortRenderingFacet = FALSE; + + /** * Returns the search path associated with this searcher. * * @return string @@ -191,7 +197,12 @@ abstract class FacetManagerPluginBase extends PluginBase implements FacetManager // Immediately initialize the facets. // This can be done directly because the only thing needed is // the url. - $this->initFacets(); + $rv = $this->initFacets(); + + // Stop rendering. + if (!$rv) { + $this->abortRenderingFacet = TRUE; + } } /** @@ -356,17 +367,28 @@ abstract class FacetManagerPluginBase extends PluginBase implements FacetManager if (!$pre_query_processor instanceof PreQueryProcessorInterface) { throw new FacetApiException($this->t("The processor @processor has a pre_query definition but doesn't implement the required PreQueryProcessorInterface interface", ['@processor' => $processor_configuration['processor_id']])); } - $pre_query_processor->preQuery($facet); + $return_value = $pre_query_processor->preQuery($facet); + + // Stop the rendering process. + if (!$return_value ) { + return FALSE; + } } } } } + + return TRUE; } /** * {@inheritdoc} */ public function build(FacetInterface $facet) { + if ($this->abortRenderingFacet) { + return []; + } + // It might be that the facet received here, // is not the same as the already loaded facets in the FacetManager. // For that reason, get the facet from the already loaded facets diff --git a/src/Plugin/facetapi/processor/FacetDependencyProcessor.php b/src/Plugin/facetapi/processor/FacetDependencyProcessor.php new file mode 100644 index 0000000..82463f8 --- /dev/null +++ b/src/Plugin/facetapi/processor/FacetDependencyProcessor.php @@ -0,0 +1,63 @@ +id() !== $facet->id()) { + $possible_processors[$v->id()] = $v->getName(); + } + } + + $build['dependend_processor'] = [ + '#type' => 'select', + '#title' => $this->t('Dependend processor'), + '#options' => $possible_processors, + ]; + + return $build; + } + + /** + * {@inheritdoc} + */ + public function preQuery(FacetInterface $facet) { + $all_facets = facetapi_get_enabled_facets(); + + $config = $facet->getProcessorConfigs()['facet_dependency']; + + $dependend_processor = $config['settings']['dependend_processor']; + + if (!array_key_exists($dependend_processor, $all_facets)) { + return FALSE; + } + + return TRUE; + } + +} diff --git a/src/Processor/PreQueryProcessorInterface.php b/src/Processor/PreQueryProcessorInterface.php index 10cf24f..ac0da99 100644 --- a/src/Processor/PreQueryProcessorInterface.php +++ b/src/Processor/PreQueryProcessorInterface.php @@ -21,6 +21,8 @@ interface PreQueryProcessorInterface extends ProcessorInterface { * alteration to the query was added before the query is executed in the * backend? * + * If this method returns FALSE, the facet will not be rendered. + * * @param \Drupal\facetapi\FacetInterface $queryType */ public function preQuery(FacetInterface $facet);