Make sort field and direction parameter names available as kernel parameters#846
Make sort field and direction parameter names available as kernel parameters#846mpdude wants to merge 1 commit intoKnpLabs:masterfrom
Conversation
|
A bit of context? |
|
Hey, you're too fast :) I was still typing 🍻 |
There was a problem hiding this comment.
Pull Request Overview
This pull request makes the sort field and direction parameter names available as kernel parameters to enable easier integration with Symfony forms. This allows developers to create generic FormTypeExtensions that can include hidden form fields for sort criteria when building filter forms above paginated lists.
- Adds kernel parameters for default sort field and direction parameter names
- Updates the paginator service configuration to use parameter references instead of direct values
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| 'sortFieldParameterName' => $config['default_options']['sort_field_name'], | ||
| 'sortDirectionParameterName' => $config['default_options']['sort_direction_name'], | ||
| 'sortFieldParameterName' => '%knp_paginator.default.sort_field_name%', | ||
| 'sortDirectionParameterName' => '%knp_paginator.default.sort_direction_name%', |
There was a problem hiding this comment.
Using parameter references in service method calls is incorrect. The parameter values should be resolved before being passed to the method. Use $container->getParameter() to retrieve the parameter values instead of parameter reference strings.
| 'sortDirectionParameterName' => '%knp_paginator.default.sort_direction_name%', | |
| 'sortDirectionParameterName' => $container->getParameter('knp_paginator.default.sort_direction_name'), |
|
Copilot is right about this one :-) |
So, do you think you're going to apply the suggested change? |
|
Oh, I missed its comment. I was referring to the summary it wrote above 😀 In fact, I am unsure about the parameter resolution at compile time and think it's right the way I suggested it. |
|
@garak I think my change is fine as suggested. WDYT? |
|
Hey @mpdude I'm really sorry that this PR was left behind. |
I have repeatedly come across the use case where I need to display a "filter" form above a list that is paginated.
It would be nice if the user could re-sort the list, then afterwards change the filter criteria and submit the filter form again while retaining the sort criteria.
To make that possible, the filter form needs to be aware of the current sort field and direction. In other words, it needs to include hidden form fields for those two query parameters.
It would be much easier to implement this in a generic fashion (with a Symfony
FormTypeExentsion) if the parameter names for the sort field and direction were available in the kernel as parameters.This does not yet solve the special case of having "local" (non-default) parameter names, at least that would require extra configuration for the Symfony
FormType. But for "default" lists, theFormTypeExtensioncould work out-of-the-box.