diff --git a/facets.install b/facets.install index 326bada..c788547 100644 --- a/facets.install +++ b/facets.install @@ -26,11 +26,11 @@ function facets_update_8001() { $entities = Facet::loadMultiple(); foreach ($entities as $entity) { $facetSourceId = $entity->getFacetSourceId(); - $old_ids = ['views_page:', 'views_block:', 'views_rest:']; + $old_ids = ['views_page', 'views_block', 'views_rest']; foreach ($old_ids as $id) { if (strpos($facetSourceId, $id) !== FALSE) { - $new_id = str_replace($id, 'search_api:', $facetSourceId); + $new_id = str_replace($id, 'search_api:' . $id . '__' , $facetSourceId); $entity->setFacetSourceId($new_id); $entity->save(); } diff --git a/facets.module b/facets.module index dcb4469..6fca7a4 100644 --- a/facets.module +++ b/facets.module @@ -59,14 +59,11 @@ function facets_search_api_query_alter(QueryInterface &$query) { /** @var \Drupal\facets\FacetManager\DefaultFacetManager $facet_manager */ $facet_manager = \Drupal::service('facets.manager'); - $search_id = $query->getSearchId(); - // It's safe to hardcode this to the search api scheme because this is in a // search_api_query_alter method. If this generated source is not correct, // implementing the same alter and directly calling // $manager->alterQuery($query, $your_facetsource_id); will fix that. - $search_id_array = explode(':', $search_id); - $facet_source = 'search_api:' . $search_id_array[1]; + $facet_source = 'search_api:' . str_replace(':', '__', $query->getSearchId()); // Add the active filters. $facet_manager->alterQuery($query, $facet_source); diff --git a/modules/rest_facets/src/Plugin/views/style/FacetsSerializer.php b/modules/rest_facets/src/Plugin/views/style/FacetsSerializer.php index fd0b239..89b8b17 100644 --- a/modules/rest_facets/src/Plugin/views/style/FacetsSerializer.php +++ b/modules/rest_facets/src/Plugin/views/style/FacetsSerializer.php @@ -80,7 +80,7 @@ class FacetsSerializer extends Serializer { } // Processing facets. - $facetsource_id = "search_api:{$this->view->id()}__{$this->view->getDisplay()->display['id']}"; + $facetsource_id = "search_api:views_rest__{$this->view->id()}__{$this->view->getDisplay()->display['id']}"; $facets = $this->facetsManager->getFacetsByFacetSourceId($facetsource_id); $this->facetsManager->updateResults($facetsource_id); diff --git a/modules/rest_facets/tests/src/Functional/RestIntegrationTest.php b/modules/rest_facets/tests/src/Functional/RestIntegrationTest.php index 48a0dac..e7f928c 100644 --- a/modules/rest_facets/tests/src/Functional/RestIntegrationTest.php +++ b/modules/rest_facets/tests/src/Functional/RestIntegrationTest.php @@ -64,7 +64,7 @@ class RestIntegrationTest extends FacetsTestBase { $id = 'type'; // Add a new facet to filter by content type. - $this->createFacet($name, $id, 'type', 'rest_export_1', 'search_api_rest_test_view'); + $this->createFacet($name, $id, 'type', 'rest_export_1', 'views_rest__search_api_rest_test_view'); // Use the array widget. $facet_edit_page = '/admin/config/search/facets/' . $id . '/edit'; @@ -88,7 +88,7 @@ class RestIntegrationTest extends FacetsTestBase { $name = 'Keywords'; $id = 'keywords'; // Add a new facet to filter by keywords. - $this->createFacet($name, $id, 'keywords', 'rest_export_1', 'search_api_rest_test_view'); + $this->createFacet($name, $id, 'keywords', 'rest_export_1', 'views_rest__search_api_rest_test_view'); // Use the array widget. $facet_edit_page = '/admin/config/search/facets/' . $id . '/edit'; diff --git a/src/Plugin/facets/facet_source/SearchApiDisplayDeriver.php b/src/Plugin/facets/facet_source/SearchApiDisplayDeriver.php index 16ffdde..4a4be49 100644 --- a/src/Plugin/facets/facet_source/SearchApiDisplayDeriver.php +++ b/src/Plugin/facets/facet_source/SearchApiDisplayDeriver.php @@ -40,7 +40,7 @@ class SearchApiDisplayDeriver extends FacetSourceDeriverBase { continue; } - $machine_name = $display->getDerivativeId(); + $machine_name = str_replace(':', '__', $display->getPluginId()); $plugin_derivatives[$machine_name] = [ 'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name, 'display_id' => $display_id, diff --git a/tests/src/Functional/BlockTestTrait.php b/tests/src/Functional/BlockTestTrait.php index ffb9c22..44cf2ee 100644 --- a/tests/src/Functional/BlockTestTrait.php +++ b/tests/src/Functional/BlockTestTrait.php @@ -28,7 +28,7 @@ trait BlockTestTrait { * @param string $source * Facet source. */ - protected function createFacet($name, $id, $field = 'type', $display_id = 'page_1', $source = 'search_api_test_view') { + protected function createFacet($name, $id, $field = 'type', $display_id = 'page_1', $source = 'views_page__search_api_test_view') { $facet_add_page = 'admin/config/search/facets/add-facet'; $this->drupalGet($facet_add_page); diff --git a/tests/src/Functional/IntegrationTest.php b/tests/src/Functional/IntegrationTest.php index 0dde302..324e903 100644 --- a/tests/src/Functional/IntegrationTest.php +++ b/tests/src/Functional/IntegrationTest.php @@ -137,7 +137,7 @@ class IntegrationTest extends FacetsTestBase { $facet_name = "Block view facet"; $facet_id = 'bvf'; - $this->createFacet($facet_name, $facet_id, 'type', 'block_1'); + $this->createFacet($facet_name, $facet_id, 'type', 'block_1', 'views_block__search_api_test_view'); $this->drupalPostForm(NULL, ['facet_settings[only_visible_when_facet_source_is_visible]' => FALSE], 'Save'); // Place the views block in the footer of all pages. @@ -348,13 +348,13 @@ class IntegrationTest extends FacetsTestBase { // Configure the facet source by selecting one of the Search API views. $this->drupalGet($facet_add_page); - $this->drupalPostForm(NULL, ['facet_source_id' => 'search_api:search_api_test_view__page_1'], 'Configure facet source'); + $this->drupalPostForm(NULL, ['facet_source_id' => 'search_api:views_page__search_api_test_view__page_1'], 'Configure facet source'); // Fill in all fields and make sure the 'field is required' message is no // longer shown. $facet_source_form = [ - 'facet_source_id' => 'search_api:search_api_test_view__page_1', - 'facet_source_configs[search_api:search_api_test_view__page_1][field_identifier]' => 'type', + 'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1', + 'facet_source_configs[search_api:views_page__search_api_test_view__page_1][field_identifier]' => 'type', ]; $this->drupalPostForm(NULL, $facet_source_form, 'Save'); @@ -542,8 +542,8 @@ class IntegrationTest extends FacetsTestBase { $this->assertResponse(200); // Check that the expected facet sources and the owl facet are shown. - $this->assertText('search_api:search_api_test_view__block_1'); - $this->assertText('search_api:search_api_test_view__page_1'); + $this->assertText('search_api:views_block__search_api_test_view__block_1'); + $this->assertText('search_api:views_page__search_api_test_view__page_1'); $this->assertText($name); // Delete the view on which both facet sources are based. @@ -554,8 +554,8 @@ class IntegrationTest extends FacetsTestBase { // and the facet/facet source are deleted. $this->drupalGet('/admin/config/search/facets'); $this->assertResponse(200); - $this->assertNoText('search_api:search_api_test_view__page_1'); - $this->assertNoText('search_api:search_api_test_view__block_1'); + $this->assertNoText('search_api:views_page__search_api_test_view__page_1'); + $this->assertNoText('search_api:views_block__search_api_test_view__block_1'); $this->assertNoText($name); } @@ -582,8 +582,8 @@ class IntegrationTest extends FacetsTestBase { $this->assertResponse(200); // Check that the expected facet sources and the owl facet are shown. - $this->assertText('search_api:search_api_test_view__block_1'); - $this->assertText('search_api:search_api_test_view__page_1'); + $this->assertText('search_api:views_block__search_api_test_view__block_1'); + $this->assertText('search_api:views_page__search_api_test_view__page_1'); $this->assertText($name); // Delete the view display for the page. @@ -595,8 +595,8 @@ class IntegrationTest extends FacetsTestBase { // and the facet/facet source are deleted. $this->drupalGet('/admin/config/search/facets'); $this->assertResponse(200); - $this->assertNoText('search_api:search_api_test_view__page_1'); - $this->assertText('search_api:search_api_test_view__block_1'); + $this->assertNoText('search_api:views_page__search_api_test_view__page_1'); + $this->assertText('search_api:views_block__search_api_test_view__block_1'); $this->assertNoText($name); } @@ -767,7 +767,7 @@ class IntegrationTest extends FacetsTestBase { // Configure the facet source by selecting one of the Search API views. $this->drupalGet($facet_add_page); - $this->drupalPostForm(NULL, ['facet_source_id' => 'search_api:search_api_test_view__page_1'], 'Configure facet source'); + $this->drupalPostForm(NULL, ['facet_source_id' => 'search_api:views_page__search_api_test_view__page_1'], 'Configure facet source'); // The field is still required. $this->drupalPostForm(NULL, $form_values, 'Save'); @@ -776,8 +776,8 @@ class IntegrationTest extends FacetsTestBase { // Fill in all fields and make sure the 'field is required' message is no // longer shown. $facet_source_form = [ - 'facet_source_id' => 'search_api:search_api_test_view__page_1', - 'facet_source_configs[search_api:search_api_test_view__page_1][field_identifier]' => $facet_type, + 'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1', + 'facet_source_configs[search_api:views_page__search_api_test_view__page_1][field_identifier]' => $facet_type, ]; $this->drupalPostForm(NULL, $form_values + $facet_source_form, 'Save'); $this->assertNoText('field is required.'); @@ -804,10 +804,10 @@ class IntegrationTest extends FacetsTestBase { $form_values = [ 'name' => $facet_name, 'id' => $facet_id, - 'facet_source_id' => 'search_api:search_api_test_view__page_1', + 'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1', ]; - $facet_source_configs['facet_source_configs[search_api:search_api_test_view__page_1][field_identifier]'] = $facet_type; + $facet_source_configs['facet_source_configs[search_api:views_page__search_api_test_view__page_1][field_identifier]'] = $facet_type; // Try to submit a facet with a duplicate machine name after form rebuilding // via facet source submit. diff --git a/tests/src/FunctionalJavascript/WidgetJSTest.php b/tests/src/FunctionalJavascript/WidgetJSTest.php index 0cb6fc2..8dc0ab5 100644 --- a/tests/src/FunctionalJavascript/WidgetJSTest.php +++ b/tests/src/FunctionalJavascript/WidgetJSTest.php @@ -52,10 +52,10 @@ class WidgetJSTest extends JavascriptTestBase { // Select one of the options from the facet source dropdown and wait for the // result to show. - $page->selectFieldOption('edit-facet-source-id', 'search_api:search_api_test_view__page_1'); + $page->selectFieldOption('edit-facet-source-id', 'search_api:views_page__search_api_test_view__page_1'); $this->getSession()->wait(6000, "jQuery('.facet-source-field-wrapper').length > 0"); - $page->selectFieldOption('facet_source_configs[search_api:search_api_test_view__page_1][field_identifier]', 'type'); + $page->selectFieldOption('facet_source_configs[search_api:views_page__search_api_test_view__page_1][field_identifier]', 'type'); // Check that after choosing the field, the name is already filled in. $field_value = $this->getSession()->getPage()->findField('edit-name')->getValue(); @@ -74,7 +74,7 @@ class WidgetJSTest extends JavascriptTestBase { 'id' => $id, 'name' => strtoupper($id), 'url_alias' => $id, - 'facet_source_id' => 'search_api:search_api_test_view__page_1', + 'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1', 'field_identifier' => 'type', 'empty_behavior' => ['behavior' => 'none'], 'widget' => [ @@ -133,7 +133,7 @@ class WidgetJSTest extends JavascriptTestBase { 'id' => $id, 'name' => strtoupper($id), 'url_alias' => $id, - 'facet_source_id' => 'search_api:search_api_test_view__page_1', + 'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1', 'field_identifier' => 'type', 'empty_behavior' => ['behavior' => 'none'], 'widget' => [ diff --git a/tests/src/Kernel/Entity/FacetFacetSourceTest.php b/tests/src/Kernel/Entity/FacetFacetSourceTest.php index 45987cb..f2eb5d8 100644 --- a/tests/src/Kernel/Entity/FacetFacetSourceTest.php +++ b/tests/src/Kernel/Entity/FacetFacetSourceTest.php @@ -83,10 +83,10 @@ class FacetFacetSourceTest extends EntityKernelTestBase { $facet_sources = $this->container ->get('plugin.manager.facets.facet_source') ->getDefinitions(); - $this->assertArrayHasKey('search_api:search_api_test_view__page_1', $facet_sources); + $this->assertArrayHasKey('search_api:views_page__search_api_test_view__page_1', $facet_sources); // Check the behavior of the facet sources. - $display_name = 'search_api:search_api_test_view__page_1'; + $display_name = 'search_api:views_page__search_api_test_view__page_1'; $entity->setFacetSourceId($display_name); $this->assertEquals($display_name, $entity->getFacetSourceId()); $this->assertInstanceOf(SearchApiDisplay::class, $entity->getFacetSources()[$display_name]); @@ -104,7 +104,7 @@ class FacetFacetSourceTest extends EntityKernelTestBase { public function testInvalidQueryType() { $entity = new Facet([], 'facets_facet'); $entity->setWidget('links'); - $entity->setFacetSourceId('search_api:search_api_test_view__page_1'); + $entity->setFacetSourceId('search_api:views_page__search_api_test_view__page_1'); $this->setExpectedException('Drupal\facets\Exception\InvalidQueryTypeException'); $entity->getQueryType();