Facet selection isn't maintained when a new sort option is chosen.

Created on 2 November 2023, about 1 year ago

Problem/Motivation

The sort widget lets the user select a new field to sort by.

If some facets have been selected by the prior to selecting a new field via the widget this module provides, the facet selection is lost after the widget choice has been submitted.

Steps to reproduce

Interact with

  • a Views view containing:
  • a Facet API facet filter block
  • a Search Api Sorts Widget block
  • Narrow results listed using one or more facets
  • Select a new sort option using the sort widget block.
  • Observe the facet selection has been lost.

Proposed fix

The URLs used to direct the client on submission of the widget form, are provided at form build and passed to the submit handler via $form_state.

Because the facet query parameters are attached to the URL using AJAX requests, the block containing the widget form isn't reloaded; which means the URLs passed to the submit handler are stale (and don't contain the necessary facet query parameters).

This causes the facet selection to be lost.

To remedy this, we can obtain the necessary URLS via calls to the request stack within the submit handler; negating the need for the values to passed when the form is built.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom lukus

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

Comments & Activities

Production build 0.71.5 2024