Ajax facet block seems to lose Views context (filters, etc)

Created on 19 July 2018, almost 6 years ago
Updated 5 May 2023, about 1 year ago

With current dev i experience a ajax facets block issue that is not there without ajax.

How to reproduce:

  • Have content types "event" and "organisation"
  • Have a view that lists both types, with an optional context from path like view/%type, so we have view/event, view/organisation, and view/all
  • Have one facet block based on an event field and one based on an organisation field for that view page
  • go to view/organisation (so the view context "content type" is "organisation")

expected:

  • on view/organisation, only facets from type "organisation" are shown

experienced without ajax:

  • works as expected

experienced with ajax enabled:

  • works as expected on first page load
  • when clicking a facet item: facets block shows facets from event and organisation

So it looks like ajax does not see the "organisation" context.

πŸ› Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany geek-merlin Freiburg, Germany

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States AndySipple

    Patch #33 πŸ› Ajax facet block seems to lose Views context (filters, etc) RTBC worked for me.
    My current use case.
    Drupal views with an exposed filter search input and exposed and the filters are exposed as a block and the view is an exposed block.
    Ajax turned on for the view using with combination with views ajax history module β†’ and this patch πŸ› Facets searches don't update results RTBC .

    Now ajax works and respects facets + the views exposed filter yay!

    Current markup with inside a paragraph using twig tweaks:

    {# Site search view exposed form #}
    <div class="search-form-container">
    {{ drupal_entity('block', 'site_search_form', check_access=false) }}
    </div>
    {# Facets #}
    <div class="facets-container">
      {{ drupal_block('facet_block:content_type') }}
      {{ drupal_block('facet_block:subject') }}
      {{ drupal_block('facet_block:media') }}
    </div>
    {# Site search view exposed form #}
    {{ drupal_view('site_search', 'site_search_default') }}
    
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    Patch Failed to Apply
  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    @burnellw_cit , patches should be created relative to the module, not your project.

    You should also rely on composer to apply properly rolled patches such as patch number 32

    https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa... β†’

  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    @burnellw_cit,
    A properly rolled patch looks like this:

    diff --git a/src/Plugin/facets/facet_source/SearchApiDisplay.php b/src/Plugin/facets/facet_source/SearchApiDisplay.php
    index 017f34f..7eac4b1 100644
    --- a/src/Plugin/facets/facet_source/SearchApiDisplay.php
    +++ b/src/Plugin/facets/facet_source/SearchApiDisplay.php

    Yours was made relative to your project, is incorrect.

    diff --git a/modules/contrib/facets/src/Plugin/facets/facet_source/SearchApiDisplay.php b/modules/contrib/facets/src/Plugin/facets/facet_source/SearchApiDisplay.php
    index d5b7042d..4a6d2510 100644
    --- a/modules/contrib/facets/src/Plugin/facets/facet_source/SearchApiDisplay.php
    +++ b/modules/contrib/facets/src/Plugin/facets/facet_source/SearchApiDisplay.php
    

    If you used composer to specify patches you would be able to use correctly rolled patches such as patch #32.

    Please review this with esteemed colleagues , for further assistance please reach out to someone on slack in the Drupal channels or on https://drupalchat.me . Your organisation may have to change it's process/build slightly to adhere to built norms.

  • First commit to issue fork.
  • πŸ‡³πŸ‡±Netherlands nickvanboven

    I have created a fork with the changes from #32 and added a check for the route object, this can be null if the request is serialized and used at a other time, we use this to get the view options on cron when processing some jobs.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    424 pass, 2 fail
  • @nickvanboven opened merge request.
  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    @nickvanboven, the 2 fails seen in MR 137 comment#40 not related to your changes.

    πŸ› HEAD tests failing since March 23, 2023 Closed: duplicate

Production build 0.69.0 2024