-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.2] Fallback parameter for UrlGenerator::previous #14207
Conversation
This has come up before and I still stand by my case of if you need a fallback then the whole point of this method is useless and shouldn't be used at all. Is there a strong reason you need a fallback? |
I'll give you a use case: In an administrator area, there is a page listing Models of some sort in a table. Next to each item you have an edit button. Each item can be clicked, directing the administrator to the single Model page. Each Model page has an edit button. The edit form has a cancel button. When the user clicks the edit button from the list page and then clicks the cancel button, the user should return to the list page. When the user clicks the edit button on the Model page and then clicks the cancel button, the user should return to the Model page. Finally, if the user visited the edit page directly, the user should return to the list page. In the last scenario, the user would be redirected to the root url when I use the |
{ | ||
$referrer = $this->request->headers->get('referer'); | ||
|
||
$url = $referrer ? $this->to($referrer) : $this->getPreviousUrlFromSession(); | ||
|
||
return $url ?: $this->to('/'); | ||
return $url ?: (value($fallback) ?: $this->to('/')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like nested ternarys.
@vlakoff can you explain? |
If there is no referer and a fallback is provided, |
In addition, |
It is wrapped in a to when I merged it. I modified the PR. |
Got it: a8ca2b7 Thoughts about my previous comments? |
Allows passing a fallback value to the
UrlGenerator::previous()
method. This parameter is optional, and if not provided will still fall back toUrlGenerator::to('/')
.