Add "extraParams" config to the SearchBehavior.#361
Conversation
This allows preserving query params for which filters are not defined and making those values available to filters (for e.g. callback filter)
There was a problem hiding this comment.
Pull Request Overview
This PR introduces an extraParams configuration option to the SearchBehavior that allows preserving query string parameters that don't have corresponding search filters defined. This enables callback filters to access values from multiple fields without requiring dummy filters for each field.
Key Changes
- Added
extraParamsconfiguration to preserve query params without filters - Modified the Processor class to merge extra params into the filtered parameters
- Updated documentation to reflect the new feature and replaced the multi-field callback workaround section
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Processor.php | Added _extraParams property, setExtraParams() method, and logic to merge extra params in _extractParams() |
| src/Model/SearchTrait.php | Added _extraParams() method returning empty array by default and integrated with processor |
| src/Model/Behavior/SearchBehavior.php | Added extraParams config option with default empty array and override for _extraParams() method |
| tests/TestCase/Model/Behavior/SearchBehaviorTest.php | Added test case verifying extra params are passed to callback filters alongside regular filter params |
| docs/additional-docs.md | Added new "Extra Parameters" section documenting the feature with usage examples |
| docs/filters-and-examples.md | Removed "Multi-field Search Callbacks" section that documented workarounds now obsoleted by extraParams feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| ---------- | ||
|
|
||
| ## Multi-field Search Callbacks |
There was a problem hiding this comment.
IMO those are still valid strategies still for specific use cases, where those are specific to only one filter.
There was a problem hiding this comment.
Using an array is a valid use case, but the empty callback is surely a hack I don't want to promote once we have a proper config based solution.
This allows preserving query params for which filters are not defined and making those values available to filters (for e.g. callback filter)