Commit fe311204 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2827808 by borisson_: Facets on multilangual site

parent 9064a63c
......@@ -146,3 +146,10 @@ the chosen module (and others, probably) doesn't find the select element.
So the library should be attached to the block in custom code, we haven't done
this in facets because we don't want to support all possible frameworks.
See https://www.drupal.org/node/2853121 for more information.
Q: Why are facets results links from another language showing in the facet
results?
A: Facets use the same limitations as the query object passed, so when using
views, add a filter to the view to limit to one language.
Otherwise, this is solved by adding a `hook_search_api_query_alter()` that
limits the results to the current language.
......@@ -151,6 +151,57 @@ class LanguageIntegrationTest extends FacetsTestBase {
$this->clickLink('item');
$this->assertTrue(strpos($this->getUrl(), 'xx-lolspeak/'), 'Found the language code in the url');
$this->assertTrue(strpos($this->getUrl(), 'tyto_alba'), 'Found the facet in the url');
}
/**
* Tests facets where the count is different per language.
*
* @see https://www.drupal.org/node/2827808
*/
public function testLanguageDifferences() {
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_mulrev_changed');
$entity_test_storage->create([
'name' => 'foo bar baz',
'body' => 'test test',
'type' => 'item',
'keywords' => ['orange', 'lol'],
'category' => 'item_category',
'langcode' => 'xx-lolspeak',
])->save();
$entity_test_storage->create([
'name' => 'foo bar baz',
'body' => 'test test',
'type' => 'item',
'keywords' => ['orange', 'rofl'],
'category' => 'item_category',
'langcode' => 'xx-lolspeak',
])->save();
$id = 'water_bear';
$this->createFacet('Water bear', $id, 'keywords');
$this->drupalGet('admin/config/search/search-api/index/' . $this->indexId . '/edit');
$this->assertEquals(2, $this->indexItems($this->indexId), '2 items were indexed.');
$this->drupalGet('search-api-test-fulltext');
$this->assertFacetBlocksAppear();
$this->assertSession()->pageTextContains('orange');
$this->assertSession()->pageTextContains('grape');
$this->assertSession()->pageTextContains('rofl');
$this->drupalPostForm(NULL, ['language' => 'xx-lolspeak'], 'Search');
$this->assertFacetBlocksAppear();
$this->assertSession()->pageTextContains('orange');
$this->assertSession()->pageTextContains('rofl');
$this->assertSession()->pageTextNotContains('grape');
$this->drupalPostForm(NULL, ['language' => 'en'], 'Search');
$this->assertFacetBlocksAppear();
$this->assertSession()->pageTextContains('orange');
$this->assertSession()->pageTextContains('grape');
$this->assertSession()->pageTextNotContains('rofl');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment