Facets exposed form block is empty if not on views page

Created on 8 October 2024, about 2 months ago

Problem/Motivation

We've set up a views page to show Search API results, that can be filtered through facets.
This view has page display with " Exposed form in block: Yes"

When being on that views page, the exposed form in block shows up correctly and all exposed facet filters are present.

On all other pages, the exposed form block appears, but the exposed facet filters are missing.

The expected result (and I'm really sure it was that way last year in the early days of 3.0.x) is to show the filters also on other pages, so if users are filtering in the block, they are redirected to the original views page.

It would be great to be able to use the exposed filter form like this, as I think this isn't a super special use-case and I think it worked before.

Any ideas? I couldn't find a workaround or the root cause in code.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇧🇪Belgium RandalV

    I'm also experiencing this issue in a new project of ours using Facets 3.0.0-beta4, exactly as described above.

    On the view page itself, everything is fine. Anywhere else, all the facets are empty :(

    I'll see if I can find anything, haven't had the time yet to debug.

  • 🇧🇪Belgium RandalV

    I haven't got the time to fully debug this in facets itself, but in my case it was solvable by rendering it in a custom block like below.
    I had to render in a custom block anyway because I wanted to add extra items before and after the exposed filters, so this was a quick fix for me.

    /** @var \Drupal\views\Plugin\Block\ViewsExposedFilterBlock $plugin_block */
    $plugin_block = $this->blockManager->createInstance('views_exposed_filter_block:events-overview');
    
    // Make sure the facets are populated.
    $view = $plugin_block->getViewExecutable();
    $view->preExecute();
    $view->execute();
    
    return [
      // ...
      'filters' => $plugin_block->build(),
      // ...
    ];
    
Production build 0.71.5 2024