Problem/Motivation

We have a use case to preserve the search input that was used, which provides a better UX for the user in the long run.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

droath created an issue. See original summary.

droath’s picture

Status: Active » Needs review
StatusFileSize
new1.95 KB
droath’s picture

phjou’s picture

Nice feature.
Should we make this a checkbox in the block configuration to enable or disable this feature? And we would enable this by default.

- If people want to customize in their theme, it might be best to have an option to not add any javascript (potential js conflict). (disable that feature)
- It might be best if the javascript was based on a class that we add ourselves because in a theme the class "form-search" could be missing or used in other spots.

phjou’s picture

Status: Needs review » Needs work
lus’s picture

I thought about something like this:

vivek panicker’s picture

Status: Needs work » Needs review
StatusFileSize
new875 bytes

This patch worked for me!

vivek panicker’s picture

Converted patch#7 to MR.

atul_ghate’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new903.61 KB
new1.81 MB

I have reproduced the issue successfully.
The MR8 is applied cleanly.

I followed the steps below to reproduce the issue:

1.Cloned the 1.0.x version of the module.
2.Installed its dependencies and enabled both modules.
3.Create a view for content and add exposed filter and configure
4.add serach api form by configuring it with key and action view url
5.Reproduced the issue both without MR8 changes and with MR8 applied.
Changing its status to RTBC.

phjou’s picture

Status: Reviewed & tested by the community » Needs work

I would probably set the cache to only be set on the query parameter and not the whole URL. That way we have a unique cache when the parameter is not there.

$form['#cache']['contexts'][] = 'url.query_args:' . $input_name;

PS: I didn't test this code, just followed the documentation:
https://www.drupal.org/docs/drupal-apis/cache-api/cache-contexts

kir lazur’s picture

StatusFileSize
new1.09 KB

here's updated version of patch

vivek panicker’s picture

@phjou I agree your solution is better. The cache variation then would only depend on the specific query argument based on the input field name and not on the entire URL. So even if other query args are present, the cached data would ignore those.

sachbearbeiter’s picture

Btw. cool feature : )

phjou’s picture

I guess we want to set the context only if the input name is not empty. Otherwise it looks good

if (!empty($input_name)) {
  $form['#cache']['contexts'][] = 'url.query_args:' . $input_name;
}

  • phjou committed a72ce7ad on 1.0.x authored by vivek panicker
    Issue #3320560: Added default value and cache context to search api form...
phjou’s picture

Status: Needs work » Fixed
vivek panicker’s picture

Hey @phjou! Thank you for merging the fix!

I would just like to inform you that according to the latest update, the maintainer has to manually provide credits to the involved participants in the Credit and Committing section in the issue.

So if anyone deserves credit here, kindly do give them! :)

phjou’s picture

phjou’s picture

@vivek Thanks for the reminder, I added the credits. I was too used to the time where the checkboxes were checked by default when somebody was uploading a file.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.