Commit a6bfdc75 authored by Markus Kalkbrenner's avatar Markus Kalkbrenner Committed by Markus Kalkbrenner
Browse files

Issue #3270708 by mkalkbrenner: Hide sibliblings should work for non-hierarchical facets, too

parent dbc7ac2b
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ use Drupal\facets\Processor\ProcessorPluginBase;
 * @FacetsProcessor(
 *   id = "hide_inactive_siblings_processor",
 *   label = @Translation("Hide inactive siblings"),
 *   description = @Translation("In case that a result item belongs to different branches of a hierarchy it the hierarchical facet might show inactive fragments of other branches. This filter will hide these fragments. It could be combined with 'Show siblings' to only display the siblings of active items."),
 *   description = @Translation("In case that a result item belongs to different branches of a hierarchy it the hierarchical facet might show inactive fragments of other branches. This filter will hide these fragments. It could be combined with 'Show siblings' to only display the siblings of active items. In case of a non-hierarchical facet, all non-active options will be hidden after the selection has been made."),
 *   stages = {
 *     "build" = 10
 *   }
@@ -25,9 +25,10 @@ class HideInactiveSiblingsProcessor extends ProcessorPluginBase implements Build
   */
  public function build(FacetInterface $facet, array $results) {
    $facet_results = $facet->getResults();
    $active_items = $facet->getActiveItems();

    if ($facet->getUseHierarchy()) {
      $hierarchy = $facet->getHierarchyInstance();
      $active_items = $facet->getActiveItems();

      if (!$facet->getKeepHierarchyParentsActive()) {
        $parents_of_active_items = [];
@@ -46,6 +47,13 @@ class HideInactiveSiblingsProcessor extends ProcessorPluginBase implements Build
        }
      }
    }
    elseif ($active_items) {
      foreach ($facet_results as $id => $result) {
        if (!$result->isActive()) {
          unset($results[$id]);
        }
      }
    }

    return $results;
  }