Facets exposed form block is empty if not on views page

Created on 8 October 2024, 11 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

Merge Requests

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(),
      // ...
    ];
    
  • First commit to issue fork.
  • 🇫🇷France mattlc

    Drupal\ayout_builder\EventSubscriber\BlockComponentRenderArray directly calls "build()" method and do not call hook_block_build_alter. So in layout builder context, view may not have been executed (if view results block is not a component before exposed form block).

    My context :
    I have same issue using a view with one block for exposed filters and one block for results.
    The blocks are set in a page via page_manager using layout builder with 2 columns section.

    Something I noticed is that the bug depends on how the blocks are organized in the page :

    Case 1 :
    - column 1 : exposed filters block
    - column 2 : results block
    => Facets are not displayed

    Case 2 :
    - column 1 : results block
    - column 2 : exposed filters block
    => Facets are well displayed

    In both cases, facets_exposed_filters_block_build_alter is never called.

    Adding an event subscriber that listens "section_component.build.render_array" solved the issue.
    I tried to not add any dependency to layout builder module this is why I use event name as String and Event Class.

  • Pipeline finished with Failed
    7 days ago
    Total: 621s
    #593709
Production build 0.71.5 2024