diff --git a/src/Form/FacetSettingsForm.php b/src/Form/FacetSettingsForm.php index d194ba4..a73bd56 100644 --- a/src/Form/FacetSettingsForm.php +++ b/src/Form/FacetSettingsForm.php @@ -313,7 +313,8 @@ class FacetSettingsForm extends EntityForm { // Search API display. if (isset($facet_source) && $facet_source instanceof FacetSourcePluginInterface) { $facet_source_display_id = $facet_source->getPluginDefinition()['display_id']; - $search_api_display = \Drupal::service('plugin.manager.search_api.display')->createInstance($facet_source_display_id); + $search_api_display = \Drupal::service('plugin.manager.search_api.display') + ->createInstance($facet_source_display_id); $search_api_display_definition = $search_api_display->getPluginDefinition(); // Get the view of the Search API display and disable caching. diff --git a/tests/src/Functional/IntegrationTest.php b/tests/src/Functional/IntegrationTest.php index 46da24b..62d145b 100644 --- a/tests/src/Functional/IntegrationTest.php +++ b/tests/src/Functional/IntegrationTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\facets\Functional; use Drupal\Core\Url; use Drupal\facets\Entity\Facet; use Drupal\views\Entity\View; +use Drupal\views\Views; /** * Tests the overall functionality of the Facets admin UI. @@ -770,6 +771,34 @@ class IntegrationTest extends FacetsTestBase { } /** + * Check that the disabling of the cache works. + */ + public function testViewsCacheDisable() { + // Load the view, verify cache settings. + $view = Views::getView('search_api_test_view'); + $view->setDisplay('page_1'); + $current_cache = $view->display_handler->getOption('cache'); + $this->assertEquals('none', $current_cache['type']); + $view->display_handler->setOption('cache', ['type' => 'tag']); + $view->save(); + $current_cache = $view->display_handler->getOption('cache'); + $this->assertEquals('tag', $current_cache['type']); + + // Create a facet and check for the cache disabled message. + $id = "western_screech_owl"; + $name = "Western screech owl"; + $this->createFacet($name, $id); + $this->drupalPostForm('admin/config/search/facets/' . $id . '/settings', [], 'Save'); + $this->assertSession()->pageTextContains('Caching of view Search API Test Fulltext search view has been disabled.'); + + // Check the view's cache settings again to see if they've been updated. + $view = Views::getView('search_api_test_view'); + $view->setDisplay('page_1'); + $current_cache = $view->display_handler->getOption('cache'); + $this->assertEquals('none', $current_cache['type']); + } + + /** * Configures empty behavior option to show a text on empty results. * * @param string $facet_name