-
Notifications
You must be signed in to change notification settings - Fork 201
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
SF 4.3 - Voters - theirs order and auto-registration as service #411
Comments
if you autoconfigure your services (which is the default behavior in a Symfony 4 app based on the Flex skeleton), a service implementing the VoterInterface will automatically be tagged as Voters can have a priority to control their order. But that will require tagging them as voter explicitly (the autoconfigured tag does not specify a priority, which makes it fallback to |
Thank you for clarification. Based on what you have described, I have to manually tagged voters and provide priority order. However when I tagged voters manually in services.yaml my custom voter in matcher is duplicated. app.voter.route:
class: Knp\Menu\Matcher\Voter\RouteVoter
arguments: [ '@request_stack' ]
tags:
- { name: knp_menu.voter, priority: 0 }
app.voter.parent:
class: App\Menu\Voter\RequestParentRouteVoter
arguments: [ '@request_stack' ]
tags:
- { name: knp_menu.voter, priority: 1 } When matcher is initialized there are 3 voters: App\Menu\Voter\RequestParentRouteVoter <- custom voter edited I figured it out where was the problem. Autoconfigured voters are always added to array with index 0. So I have to add default RouteVoter with priority 2 and my custom voter with priority 1. The order of voters for item which wasn't recognized is as follows: (first voter to be run is on top)
|
I created new Voter in src\Menu\Voter directory. I was surprised that I didn't have to register that voter as a service in services.yaml. Voter just started to work without any other action from my side. Is it normal behaviour because I used menu directory name which is the directory of the bundle?
My Voter was added before default one to the matcher's voters array. I would like to change the order of voters that my voter would be the last one. Is it possible? If not can I (I mean is it good solution) just create new class and extends Knp\Menu\Matcher\Matcher class to overwrite constructor and reverse order of already added voters?
The text was updated successfully, but these errors were encountered: