diff --git a/src/Form/FacetForm.php b/src/Form/FacetForm.php index 4f7b77f..c1be783 100644 --- a/src/Form/FacetForm.php +++ b/src/Form/FacetForm.php @@ -196,7 +196,10 @@ public function form(array $form, FormStateInterface $form_state) { $stages = $this->processorPluginManager->getProcessingStages(); $processors_by_stage = []; foreach ($stages as $stage => $definition) { - $processors_by_stage[$stage] = $facet->getProcessorsByStage($stage, FALSE); + $processors_by_stage[$stage] = array_filter($facet->getProcessorsByStage($stage, FALSE), function ($id) use ($facet) { + $processor = $this->processorPluginManager->createInstance($id, ['facet' => $facet]); + return $processor->supportsFacet($facet); + }, ARRAY_FILTER_USE_KEY); } $form['#tree'] = TRUE; diff --git a/tests/facets_custom_widget/src/Plugin/facets/processor/TestPreQuery.php b/tests/facets_custom_widget/src/Plugin/facets/processor/TestPreQuery.php index 363af25..9b9f1da 100644 --- a/tests/facets_custom_widget/src/Plugin/facets/processor/TestPreQuery.php +++ b/tests/facets_custom_widget/src/Plugin/facets/processor/TestPreQuery.php @@ -39,4 +39,11 @@ public function preQuery(FacetInterface $facet) { drupal_set_message($this->getConfiguration()['test_value']); } + /** + * {@inheritdoc} + */ + public function supportsFacet(FacetInterface $facet) { + return \Drupal::state()->get('facets_test_supports_facet', TRUE); + } + } diff --git a/tests/facets_custom_widget/src/Plugin/facets/widget/CustomWidget.php b/tests/facets_custom_widget/src/Plugin/facets/widget/CustomWidget.php index 9e67dd5..9b7186f 100644 --- a/tests/facets_custom_widget/src/Plugin/facets/widget/CustomWidget.php +++ b/tests/facets_custom_widget/src/Plugin/facets/widget/CustomWidget.php @@ -2,6 +2,7 @@ namespace Drupal\facets_custom_widget\Plugin\facets\widget; +use Drupal\facets\FacetInterface; use Drupal\facets\Widget\WidgetPluginBase; /** @@ -29,4 +30,11 @@ public function isPropertyRequired($name, $type) { return FALSE; } + /** + * {@inheritdoc} + */ + public function supportsFacet(FacetInterface $facet) { + return \Drupal::state()->get('facets_test_supports_facet', TRUE); + } + } diff --git a/tests/src/Functional/ProcessorIntegrationTest.php b/tests/src/Functional/ProcessorIntegrationTest.php index f45b630..45c3782 100644 --- a/tests/src/Functional/ProcessorIntegrationTest.php +++ b/tests/src/Functional/ProcessorIntegrationTest.php @@ -646,4 +646,25 @@ public function testPreQueryProcessor() { $this->assertSession()->pageTextContains('Llama'); } + /** + * Tests the facet support for a widget. + */ + public function testSupportsFacet() { + $id = 'masked_owl'; + $this->createFacet('Australian masked owl', $id); + + // Go the the facet edit page and check to see if the custom processor shows + // up. + $this->drupalGet('admin/config/search/facets/' . $id . '/edit'); + $this->assertSession()->pageTextContains('test pre query'); + + // Make the ::supportsFacet method on the custom processor return false. + \Drupal::state()->set('facets_test_supports_facet', FALSE); + + // Go to the facet edit page and check to see if the custom processor is + // now hidden. + $this->drupalGet('admin/config/search/facets/' . $id . '/edit'); + $this->assertSession()->pageTextNotContains('test pre query'); + } + } diff --git a/tests/src/Functional/WidgetIntegrationTest.php b/tests/src/Functional/WidgetIntegrationTest.php index f5179f7..0e821f2 100644 --- a/tests/src/Functional/WidgetIntegrationTest.php +++ b/tests/src/Functional/WidgetIntegrationTest.php @@ -152,4 +152,25 @@ public function testCustomWidget() { $this->assertSession()->checkboxChecked('edit-facet-settings-show-only-one-result'); } + /** + * Tests the facet support for a widget. + */ + public function testSupportsFacet() { + $id = 'masked_owl'; + $this->createFacet('Australian masked owl', $id); + + // Go the the facet edit page and check to see if the custom widget shows + // up. + $this->drupalGet('admin/config/search/facets/' . $id . '/edit'); + $this->assertSession()->pageTextContains('Custom widget'); + + // Make the ::supportsFacet method on the custom widget return false. + \Drupal::state()->set('facets_test_supports_facet', FALSE); + + // Go to the facet edit page and check to see if the custom widget is now + // hidden. + $this->drupalGet('admin/config/search/facets/' . $id . '/edit'); + $this->assertSession()->pageTextNotContains('Custom widget'); + } + }