Skip to content

Page parameter name - #820

Merged
garak merged 7 commits into
KnpLabs:masterfrom
matatirosolutions:pageParameterName
Feb 28, 2025
Merged

garak merged 7 commits into
KnpLabs:masterfrom
matatirosolutions:pageParameterName

Conversation

@steveWinter

Copy link
Copy Markdown
Contributor

This PR resolves #815 in the manner suggested by @garak in that issue - passing the entire SlidingPagination object to the templates to allow the pageParameterName to be accessed.

In the future it would likely be possible to remove some of the local variables which are created as the template is being rendered since they could be accessed directly from the SlidingPagination, however I wanted to keep this PR to solving just the issue at hand.

@garak

garak commented Feb 15, 2025

Copy link
Copy Markdown
Collaborator

Do we really need to pass the entire Pagination object? I think passing only the options array can be enough.

@steveWinter

steveWinter commented Feb 16, 2025 •

Copy link
Copy Markdown
Contributor Author

Hi @garak in this comment on the issue you said

Probably we should pass the entire set of options to the PaginationRuntime constructor, while currently we pass only a few.

Did I miss-understand what you had meant? Or not implement it in the way you expected?

Essentially I took the code you proposed, updated it slightly for changed variable names, then modified the templates to pass in that third parameter.

@garak

garak commented Feb 16, 2025

Copy link
Copy Markdown
Collaborator

Well, I wrote that code a few months ago. Probably I would ask the same question to the past myself: why passing the entire object, when we can pass only the options? Moreover, considering that the object is only used to retrieve the options themselves.

@steveWinter

steveWinter commented Feb 16, 2025 •

Copy link
Copy Markdown
Contributor Author

I believe your rationale was

I'm sure it works, but it would force use to extract the pageParameterName to be passed everywhere. Moreover, it's not future-proof: if one day we find in the need of another option, we would be forced to add a new argument.

How would you like me to proceed? I can modify it such that we pass only that parameter (which for reference is how is used to work in v5), or we can continue with this approach?

@garak

garak commented Feb 17, 2025 •

Copy link
Copy Markdown
Collaborator

Change the method to accept an array, pass $pagination->getOptions(), access the page parameter name from the options array.

@steveWinter

Copy link
Copy Markdown
Contributor Author

@garak thank you for your feedback - I've pushed another commit which I hope as implemented things as you intended.

Comment thread src/Helper/Processor.php Outdated

$data['route'] = $pagination->getRoute();
$data['query'] = \array_merge($pagination->getParams(), $queryParams);
$data['paginatorOptions'] = $pagination->getPaginatorOptions();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's go with "option" as name, it's simpler

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as requested

* @return array
*/
public function getQueryParams(array $query, int $page): array
public function getQueryParams(array $query, int $page, ?array $paginatorOptions = []): array

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same name change here. Moreover, we don't need to accept a null value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as requested

Comment thread src/Twig/Extension/PaginationRuntime.php
@steveWinter

Copy link
Copy Markdown
Contributor Author

Thank you for your feedback @garak - I've renamed the variable as requested. I hope that the change to make the $options parameter non-nullable will also resolve the PHPStan issue.

@garak
garak merged commit b7308c1 into KnpLabs:master Feb 28, 2025
* @return array
*/
public function getQueryParams(array $query, int $page): array
public function getQueryParams(array $query, int $page, array $options): array

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry @steveWinter I was about to release this change, but I realized this new argument would break any custom template not passing it.
We need to fix it with a default value of []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pageParameterName not supported

2 participants