Problem/Motivation

I require to alter the filter params before they are processed. There was no clean way to do it besides overriding the class or do it in a later event.

Proposed resolution

Add a AlterSearchQueryFiltersEvent that is triggered after QueryParamBuilder builds the filters, but before it builds the rest of the query (i.e.: before the filters are processed).

Remaining tasks

  1. Write an 8.0.x merge request - merge request !95 created from @marckwee's code in #4
  2. Write a 9.0.x merge request - merge request !196 created by @mparker17 in #8
  3. Community review - done by @fathershawn in #12
  4. Maintainer review - done by @mparker17 in #9
  5. Commit to 9.0.x - merged by @mparker17 in #15
  6. Commit to 8.0.x - merged by @mparker17 in #17
  7. Release 9.0.x - released in 9.0.0-alpha3 by @mparker17
  8. Release 8.0.x - released in 8.0.0-alpha7 by @mparker17

User interface changes

None.

Introduced terminology

None.

API changes

Adds an AlterSearchQueryFiltersEvent that is triggered after QueryParamBuilder builds the filters, but before it builds the rest of the query.

Data model changes

None.

Release notes snippet

Added an AlterSearchQueryFiltersEvent to modify filters created by QueryParamBuilder, before they are processed.

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

marckwee created an issue. See original summary.

marckwee’s picture

mparker17 made their first commit to this issue’s fork.

mparker17’s picture

@marckwee, thank you for the contribution! This sounds like a great idea to me!

I committed your code to a merge request to make it easier for me to review. I took a very quick look at your patch: the changes seem clear to me, but I haven't yet had a chance to run the changed code... I may have more feedback when I do.

We should add a change record to assist people upgrading from 8.x-7.x. Note we have a draft, not-complete-yet change record with some information on events that existed in the 8.x-7.x and their equivalents in 8.0.x (if applicable) — not sure if we need to update that, or create a new change record.

I didn't see any automated tests in your patch... we prefer to accept merge requests that have passing automated tests. Automated tests ultimately benefit you, because they ensure that future changes to this module (i.e.: by other people) will not break the functionality that your site depends on!

mparker17’s picture

Issue tags: +Needs issue summary update

Briefly checking the status of this issue after releasing 8.0.0-alpha5...

  1. The existing tests are passing — so this merge request didn't cause any regressions
  2. But the new code path doesn't have any tests, and it will need a test before I can merge it.
  3. We should also write a change record for this
  4. The issue summary will need to be updated before release.
mparker17’s picture

Status: Active » Needs work

I should move this to "Needs work" as well; sorry for the noise.

mparker17’s picture

Title: Add event to allow altering filter parameters before processing » Add an event to modify filter parameters before processing
Version: 8.0.0-alpha2 » 9.0.x-dev
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs change record, -Needs issue summary update +needs backport to 8.0.x, +change record added

I've updated the issue summary, added tests, a change record, and created a 9.0.x branch (because I'll merge that first). I've tagged this issue so I remember to merge both branches, and publish the change record.

Now that tests are in place, I'd like to rename the event from FilterParamsEvent to AlterSearchQueryFiltersEvent to make it clearer when this event is dispatched, so I'm going to do that next (then I will update the issue summary and change record).

mparker17’s picture

Issue summary: View changes

Okay, tests are passing, so this is ready for review.

@marckwee, I would really appreciate it if you could test the new changes, to make sure they work. Note you will have to alter the class name of the event you're listening to (i.e.: from FilterParamsEvent to AlterSearchQueryFiltersEvent). If it works, then please change the status of this ticket to "Reviewed & tested by the community".

Thank you very much in advance!

mparker17’s picture

Assigned: marckwee » Unassigned

(unassigning: anyone can provide feedback/community review!)

fathershawn’s picture

Status: Needs review » Reviewed & tested by the community

Code looks correct

mparker17’s picture

Issue summary: View changes

Awesome, thanks @fathershawn, I will merge this shortly!

mparker17’s picture

There was a merge conflict with #3554964: Add an event to modify query parameters created by QueryParamBuilder so I rebased the branches. The conflict was in test code, so if the tests pass, then I'm happy to merge - there's no need for a re-review.

  • mparker17 committed 980ae884 on 9.0.x
    feat: #3527020 Add an event to modify filter parameters before...
mparker17’s picture

Version: 9.0.x-dev » 8.0.x-dev
Issue summary: View changes
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: -needs backport to 8.0.x, -change record added

Merged to 9.0.x; change record published. Merging to 8.0.x next.

  • mparker17 committed 27631144 on 8.0.x
    feat: #3527020 Add an event to modify filter parameters before...
mparker17’s picture

Issue summary: View changes
Status: Patch (to be ported) » Fixed

Merged to 8.0.x now. I'll update this issue when this issue has been released. Thanks everyone!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

mparker17’s picture

Issue summary: View changes

The changes in this issue were released in elasticsearch_connector-9.0.0-alpha3, and elasticsearch_connector-8.0.0-alpha7

Status: Fixed » Closed (fixed)

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