Commit 01ca352d authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2930958 by borisson_, mpp: Activate the parent only when the last child is unselected

parent 3c3ceedd
......@@ -100,7 +100,22 @@ class QueryString extends UrlProcessorPluginBase {
// Enable parent id again if exists.
$parent_ids = $facet->getHierarchyInstance()->getParentIds($result->getRawValue());
if (isset($parent_ids[0]) && $parent_ids[0]) {
$filter_params[] = $this->urlAlias . $this->getSeparator() . $parent_ids[0];
// Get the parents children.
$child_ids = $facet->getHierarchyInstance()->getNestedChildIds($parent_ids[0]);
// Check if there are active siblings.
$active_sibling = FALSE;
if ($child_ids) {
foreach ($results as $result2) {
if ($result2->isActive() && $result2->getRawValue() != $result->getRawValue() && in_array($result2->getRawValue(), $child_ids)) {
$active_sibling = TRUE;
continue;
}
}
}
if (!$active_sibling) {
$filter_params[] = $this->urlAlias . $this->getSeparator() . $parent_ids[0];
}
}
}
}
......
......@@ -268,13 +268,20 @@ class HierarchicalFacetIntegrationTest extends FacetsTestBase {
$this->drupalPostForm(NULL, $edit, 'Save');
$this->drupalGet('search-api-test-fulltext');
// Enable a child under Parent 2.
$this->clickLink('Child 4');
$this->checkFacetIsActive('Child 4');
$this->clickLink('Child 3');
$this->checkFacetIsActive('Child 3');
$this->checkFacetIsActive('Child 4');
$this->checkFacetIsNotActive('Parent 2');
// Uncheck the facet again and see if Parent 2 is active now.
$this->clickLink('(-) Child 4');
$this->checkFacetIsActive('Child 3');
$this->checkFacetIsNotActive('Child 4');
$this->checkFacetIsNotActive('Parent 2');
$this->clickLink('(-) Child 3');
$this->checkFacetIsNotActive('Child 3');
$this->checkFacetIsNotActive('Child 4');
$this->checkFacetIsActive('Parent 2');
}
......
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