Commit 13c29d16 authored by gnuget's avatar gnuget Committed by borisson_

Issue #2890024 by gnuget: Wrong breadcrumb link when the filter key is empty

parent 9e01591c
......@@ -324,11 +324,12 @@ function facets_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInter
$facet_url = $res->getUrl();
/** @var \Drupal\Core\Url $facet_url */
$query = $facet_url->getOption('query');
$source_filter = isset($query[$facet_source->getFilterKey()]) ? $query[$facet_source->getFilterKey()] : [];
$filter_key = $facet_source->getFilterKey() ?: 'f';
$source_filter = $query[$filter_key];
$source_filter = array_unique($source_filter);
$source_filter = array_filter($source_filter);
$matches = preg_grep('/^' . implode('|^', $facet_used_result) . '/', $source_filter);
$query[$facet_source->getFilterKey()] = $matches;
$query[$filter_key] = $matches;
$facet_crumb_items[] = $res->getDisplayValue();
}
......
......@@ -48,16 +48,7 @@ class BreadcrumbIntegrationTest extends FacetsTestBase {
* Tests Breadcrumb integration with grouping.
*/
public function testGroupingIntegration() {
$this->drupalGet('admin/config/search/facets');
$this->clickLink('Configure', 1);
$edit = [
'filter_key' => 'f',
'url_processor' => 'query_string',
'breadcrumb[active]' => TRUE,
'breadcrumb[group]' => TRUE,
];
$this->drupalPostForm(NULL, $edit, 'Save');
$this->editFacetConfig();
$id = 'keywords';
$name = 'Keywords';
$this->createFacet($name, $id, 'keywords');
......@@ -71,6 +62,42 @@ class BreadcrumbIntegrationTest extends FacetsTestBase {
$this->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this->drupalPostForm(NULL, ['facet_settings[weight]' => '1'], 'Save');
// Test with a default filter key.
$this->editFacetConfig(['filter_key' => 'f']);
$this->breadcrumbTest();
// Test with an empty filter key.
$this->editFacetConfig(['filter_key' => '']);
$this->breadcrumbTest();
// Test with a specific filter key.
$this->editFacetConfig(['filter_key' => 'my_filter_key']);
$this->breadcrumbTest();
}
/**
* Edit the facet configuration with the given values.
*
* @param array $config
* The new configuration for the facet
*/
public function editFacetConfig(array $config = []) {
$this->drupalGet('admin/config/search/facets');
$this->clickLink('Configure', 1);
$default_config = [
'filter_key' => 'f',
'url_processor' => 'query_string',
'breadcrumb[active]' => TRUE,
'breadcrumb[group]' => TRUE,
];
$edit = array_merge($default_config, $config);
$this->drupalPostForm(NULL, $edit, 'Save');
}
/**
* Tests Breadcrumb with the given config.
*/
protected function breadcrumbTest() {
// Breadcrumb should show Keywords: orange > Type: article, item
$initial_query = ['search_api_fulltext' => 'foo', 'test_param' => 1];
......
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