Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I extend functionality of TwigFunction #756

Open
danilphd opened this issue Feb 11, 2023 · 1 comment
Open

How can I extend functionality of TwigFunction #756

danilphd opened this issue Feb 11, 2023 · 1 comment

Comments

@danilphd
Copy link

Q A
Bundle version 5.9.0
Symfony version 5.4.15
PHP version 8.1.12

Hi, first of all, thanks for your bundle.

I use knp_pagination_sortable in twig temple, but I want to generate route without default GET-parameters.
For example, default parameters: sort=price, direction=asc, page=1.
And the page https://example.com/some-page is equivalent for this https://example.com/some-page?sort=price&direction=asc&page=1

Well, I want to get first result without GET parameters, but I cann't do it simply.

Processor class:

$params = \array_merge(
    $params,
    [
        $pagination->getPaginatorOption('sortFieldParameterName') => $key,
        $pagination->getPaginatorOption('sortDirectionParameterName') => $direction,
        $pagination->getPaginatorOption('pageParameterName') => 1, // reset to 1 on sort
    ]
);

There aren't some events to modify that.

Processor class is final. I cannot extend it. PaginationExtension in constructor use Processor $processor, so I can't override service knp_paginator.helper.processor. I have only one way - make a new TwigFunction (copy knp_pagination_sortable) and made modifications.

And I want to know, is there some reason why you restrict overriding functionality? I mean most of php-class is final. No interfaces in constructor and events.

@danilphd danilphd changed the title How can I extend functionality How can I extend functionality of TwigFunction Feb 11, 2023
@garak
Copy link
Collaborator

garak commented Feb 11, 2023

The reason for restricting overriding is limiting the scope of supported files, and so being able to change something without waiting for a major release.
If you feel that implementing an interface makes sense here, you can propose a pull request.

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

No branches or pull requests

2 participants