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

Issue #2872567 by borisson_: Fix breadcrumb on php5

parent 75561ce5
......@@ -310,6 +310,7 @@ function facets_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInter
// @see https://www.drupal.org/node/2861586
// TODO handle not grouped facets.
/** @var \Drupal\facets\Result\ResultInterface[] $facet_results */
foreach ($active_results as $facet_alias => $facet_results) {
$facet_used_result[] = $facet_alias;
$facet_crumb_items = [];
......@@ -323,7 +324,7 @@ 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 = $query[$facet_source->getFilterKey()];
$source_filter = isset($query[$facet_source->getFilterKey()]) ? $query[$facet_source->getFilterKey()] : [];
$source_filter = array_unique($source_filter);
$source_filter = array_filter($source_filter);
$matches = preg_grep('/^' . implode('|^', $facet_used_result) . '/', $source_filter);
......@@ -331,6 +332,8 @@ function facets_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInter
$facet_crumb_items[] = $res->getDisplayValue();
}
sort($facet_crumb_items);
// Set the new query and create the link.
$facet_url->setOption('query', $query);
$crumb_text = $active_facets[$facet_alias]->label() . ': ' . implode(', ', $facet_crumb_items);
......@@ -338,5 +341,4 @@ function facets_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInter
$breadcrumb->addLink($link);
}
}
}
......@@ -33,7 +33,7 @@ class BreadcrumbIntegrationTest extends FacetsTestBase {
$this->setUpExampleStructure();
$this->insertExampleContent();
self::assertEquals($this->indexItems($this->indexId), 5, '5 items were indexed.');
$this->assertEquals($this->indexItems($this->indexId), 5, '5 items were indexed.');
$block = [
'region' => 'footer',
......@@ -59,41 +59,44 @@ class BreadcrumbIntegrationTest extends FacetsTestBase {
$this->drupalPostForm(NULL, $edit, 'Save');
$id = 'keywords';
$name = '#Keywords';
$name = 'Keywords';
$this->createFacet($name, $id, 'keywords');
$this->resetAll();
$this->drupalGet('admin/config/search/facets/' . $id . '/edit');
$id = 'type';
$name = '#Type';
$name = 'Type';
$this->createFacet($name, $id);
$this->resetAll();
$this->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this->drupalPostForm(NULL, ['facet_settings[weight]' => '1'], 'Save');
// Breadcrumb should show #Keywords: orange > #Type: article, item
// Breadcrumb should show Keywords: orange > Type: article, item
$initial_query = ['search_api_fulltext' => 'foo', 'test_param' => 1];
$this->drupalGet('search-api-test-fulltext', ['query' => $initial_query]);
$this->clickLink('item');
$this->assertSession()->linkExists('Type: item');
$this->clickLink('article');
$this->clickLink('orange');
$this->assertSession()->linkExists('Type: article, item');
$this->assertSession()->linkExists('#Keywords: orange');
$this->assertSession()->linkExists('#Type: article, item');
$this->clickLink('orange');
$this->assertSession()->linkExists('Keywords: orange');
$this->assertSession()->linkExists('Type: article, item');
$this->clickLink('#Type: article, item');
$this->clickLink('Type: article, item');
$this->assertSession()->linkExists('#Keywords: orange');
$this->assertSession()->linkExists('#Type: article, item');
$this->assertSession()->linkExists('Keywords: orange');
$this->assertSession()->linkExists('Type: article, item');
$this->checkFacetIsActive('orange');
$this->checkFacetIsActive('item');
$this->checkFacetIsActive('article');
$this->clickLink('#Keywords: orange');
$this->assertSession()->linkExists('#Keywords: orange');
$this->assertSession()->linkNotExists('#Type: article, item');
$this->clickLink('Keywords: orange');
$this->assertSession()->linkExists('Keywords: orange');
$this->assertSession()->linkNotExists('Type: article, item');
$this->checkFacetIsActive('orange');
$this->checkFacetIsNotActive('item');
$this->checkFacetIsNotActive('article');
......@@ -106,7 +109,7 @@ class BreadcrumbIntegrationTest extends FacetsTestBase {
/**
* Tests Breadcrumb integration without grouping.
*/
// public function testNonGroupingIntegration() {
// TODO test it after we implement non grouping functionality.
// }
public function testNonGroupingIntegration() {
$this->markTestSkipped('Not yet implemented.');
}
}
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