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
Make logout_url() and logout_path() return null if logout is not enabled? #29267
Comments
I think from a vendor/generic template perspective you should assign a variable to indicate availability, i.e.; In apps you know it works, or otherwise the exception is expected and helps you debug. With this change one might not even notice the logout helper is generating an empty url/path when doing So i think im 👎 on this. |
@ro0NL so you would agree on changing the current Twig behaviour about variables to trigger an exception when some variable is undefined instead of silently returning null? |
Yes in debug mode :) |
@javiereguiluz we're already doing that; https://github.com/symfony/recipes/blob/master/symfony/twig-bundle/3.3/config/packages/twig.yaml#L4 +
|
@ro0NL yes! I was talking about production. Right now:
This PR could be reworded as: should we make logout behave the same as vars and return null in prod? |
we can debate one should always prefer strict mode, in any environment :} For logout helper it could follow the same approach, e.g. be silent in prod. But as it's a known feature im not sure it really makes sense. It's not the point of your PR right.. which would also need silentness in dev... |
@ro0NL actually, I don't need silentness in "dev". Developers would see the exception in "dev" and fix the problem ... while normal people in "prod" wouldn't face any issue and they just wouldn't see the "log out" link. |
But then it will be fixed in prod also :) So you imply end-users modify the vendor template (they own it), which defeats checking availability dont you think. |
We could add new |
I wouldn't add |
Let's close this as "won't fix". The proposed feature is not generic/useful enough. Thanks! |
Description
When using
logout_url()
andlogout_path()
Twig functions, you may trigger an exception if logout is not enabled in the app.In an app created by you, this is not a problem. But if you are creating a template that can be used in any number of apps you don't have control over ... that's a big problem.
In EasyAdmin we display the logout URL only if logout is enabled in the app. I'd like to do this:
But I can't because
logout_path()
can throw exceptions. So we ended up recreating Symfony's LogoutUrlExtension to add atry ... catch
to it (https://github.com/EasyCorp/EasyAdminBundle/blob/39a8cf2728cae00b86ba1c072e33f45716ca5d97/src/Twig/EasyAdminTwigExtension.php#L383-L394).My questions:
null
as the logout URL when logout is not enabled?Thanks!
The text was updated successfully, but these errors were encountered: