diff --git a/src/Form/FacetForm.php b/src/Form/FacetForm.php index a6188ba..4f7b77f 100644 --- a/src/Form/FacetForm.php +++ b/src/Form/FacetForm.php @@ -129,6 +129,9 @@ public function form(array $form, FormStateInterface $form_state) { foreach ($this->widgetPluginManager->getDefinitions() as $widget_id => $definition) { $widget_options[$widget_id] = !empty($definition['label']) ? $definition['label'] : $widget_id; } + + // Filters all the available widgets to make sure that only those that + // this facet applies for are enabled. $widget_options = array_filter($widget_options, function ($widget_id) use ($facet) { $widget = $this->widgetPluginManager->createInstance($widget_id); return $widget->supportsFacet($facet); @@ -182,8 +185,11 @@ public function form(array $form, FormStateInterface $form_state) { $all_processors = $form_state->get('processors'); } $enabled_processors = $facet->getProcessors(TRUE); + + // Filters all the available processors to make sure that only those that + // this facet applies for are enabled. $all_processors = array_filter($all_processors, function ($id) use ($facet) { - $processor = $this->processorPluginManager->createInstance($id); + $processor = $this->processorPluginManager->createInstance($id, ['facet' => $facet]); return $processor->supportsFacet($facet); }, ARRAY_FILTER_USE_KEY); diff --git a/src/Processor/ProcessorInterface.php b/src/Processor/ProcessorInterface.php index d5bef84..bd6f65a 100644 --- a/src/Processor/ProcessorInterface.php +++ b/src/Processor/ProcessorInterface.php @@ -111,6 +111,19 @@ public function isHidden(); */ public function getDescription(); + /** + * Checks if the facet is supported by this widget. + * + * Reasons why this would be unsupported can be chosen by the widget. + * + * @param \Drupal\facets\FacetInterface $facet + * The facet to check for. + * + * @return bool + * Returns true when allowed, false otherwise. + * + * @see \Drupal\facets\Widget\WidgetPluginInterface::supportsFacet + */ public function supportsFacet(FacetInterface $facet); } diff --git a/src/Widget/WidgetPluginInterface.php b/src/Widget/WidgetPluginInterface.php index c5028e5..cd90d4a 100644 --- a/src/Widget/WidgetPluginInterface.php +++ b/src/Widget/WidgetPluginInterface.php @@ -51,6 +51,19 @@ public function getQueryType(array $query_types); */ public function isPropertyRequired($name, $type); + /** + * Checks if the facet is supported by this processor. + * + * Reasons why this would be unsupported can be chosen by the processor. + * + * @param \Drupal\facets\FacetInterface $facet + * The facet to check for. + * + * @return bool + * Returns true when allowed, false otherwise. + * + * @see \Drupal\facets\Processor\ProcessorInterface::supportsFacet + */ public function supportsFacet(FacetInterface $facet); /**