Reset link count ignores excluded facet items

Created on 27 May 2025, 9 days ago

The reset link count ignores excluded facet items:

Steps to reproduce:

  1. Create a facet
  2. Select widget "List of links"
  3. Under fieldset "List of links settings", enable checkbox "Show reset link"
  4. Under fieldset "Facet settings", enable checkbox "Exclude specified items" and provide a couple of values
  5. Test this facet with on a search page
  6. Expected result: the reset link count shows the total number of items displayed when no facet item is active
  7. Actual result: it shows a sum of the facet item counts that have not been excluded

I tried to tweak the processor orders under fieldset "Advanced settings", to no avail. All processors seem to run before the reset link is built in the widget class, so seems to be no way for the former to run after the latter.

As a workaround I have overridden the widget class and made my facet use that custom widget, though it would be best if this was natively supported:


class MyLinksWidget extends LinksWidget {

  /**
   * {@inheritdoc}
   */
  public function build(FacetInterface $facet) {
    $build = parent::build($facet);
    if ($facet->id() == 'my_facet_ss') {
      $exclude = [
        'rockets',
        'bikes',
      ];
      foreach ($build['#items'] as $key => $item) {
        if (in_array($item['#title']['#raw_value'], $exclude)) {
          unset($build['#items'][$key]);
        }
      }
    }
    return $build;
  }

}

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇨🇦Canada fengtan Montreal, Canada

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024