Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FrameworkBundle] Remove ControllerTrait::isFormValid()#29813
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
javiereguiluz commentedJan 8, 2019
@weaverryan I'd like to read your opinion about this. In the past you insisted a lot to add the So, my question: are you happy with the proposed shortcut name? if ($this->isFormValid($form,$request)) {... } Or would you prefer to keep being explicit about the form submission? if ($this->isFormSubmittedAndValid($form,$request)) {... }if ($this->formIsSubmittedAndValid($form,$request)) {... }... Thanks! |
lyrixx commentedJan 8, 2019
@javiereguiluz we added So let's keep thing simple here. I really prefer |
javiereguiluz commentedJan 8, 2019
I've seen lots of newcomers have problems understand where or who submits the form. With the current recommended way of working, you can easily see the "is submitted?" check: publicfunctionnew(Request$request){$task =newTask();$form =$this->createForm(TaskType::class,$task);$form->handleRequest($request);if ($form->isSubmitted() &&$form->isValid()) {// ...return$this->redirectToRoute('task_success'); }return$this->render('task/new.html.twig', ['form' =>$form->createView(), ]);} If you remove the optional My fear is that the new shortcut removes any clues about the form being submitted or processed or handled: publicfunctionnew(Request$request){$task =newTask();$form =$this->createForm(TaskType::class,$task);if ($this->isFormValid($form,$request)) {// ...return$this->redirectToRoute('task_success'); }return$this->render('task/new.html.twig', ['form' =>$form->createView(), ]);} But my fears could be exaggerated. That's why I want to know Ryan's opinion about this. Thanks! |
mbabker commentedJan 8, 2019
If the form being submitted is a condition of it being valid, then I would suggest |
weaverryan commentedJan 10, 2019 • edited by lyrixx
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by lyrixx
Uh oh!
There was an error while loading.Please reload this page.
Sorry@lyrixx, I don't really like this new shortcut, though it looks like Fab does like it, so it's certainly subjective. As Javier mentioned, with: publicfunctionnew(Request$request){$task =newTask();$form =$this->createForm(TaskType::class,$task);if ($this->isFormValid($form,$request)) {// ...return$this->redirectToRoute('task_success'); }return$this->render('task/new.html.twig', ['form' =>$form->createView(), ]);} The flow is very non-obvious. It's very strange to have a method starting with If anything, I tend to agree with Javier's suggestions:#29813 (comment) - or
Yes, but before we added |
fabpot commentedJan 10, 2019
@lyrixx With this PR, I think the shortcut has less "value". It was already quite controversial, but reading@weaverryan and@javiereguiluz comments, I think I tend to agree with them now. |
lyrixx commentedJan 10, 2019
What should I do? I'm a bit confused here :| |
javiereguiluz commentedJan 10, 2019
@lyrixx I still like this shortcut ... but I think we need to tweak it a bit to make it better. I don't have a perfect solution for this, though. As mentioned, controllers handling forms have two very different execution branches ... and this shortcut hides that too much at the moment. |
nicolas-grekas commentedJan 10, 2019
I think we should remove the method personally. |
fabpot commentedJan 10, 2019
I would vote to revert as well. |
lyrixx commentedJan 10, 2019
Are you talking about submitted vs valid ? |
javiereguiluz commentedJan 10, 2019
@lyrixx no, I was talking about creating/rendering the form vs processing the form. That's why I need the "isSubmitted()" thing ... to say,"yes! now it's when we are processing the form instead of rendering it". |
chalasr commentedJan 10, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Too much important things are hidden by this shortcut, the name does not reflect what it does. I don't expect a |
lyrixx commentedJan 10, 2019
Actually, I just wanted to replace if ($form->handleRequest($request)->isSubmitted()) &&$form->isValid()) {# code...} if ($this->isFormValid($form) {# code...} I guess I have used the following code only once if ($form->handleRequest($request)->isSubmitted()) {#code} I think I spend more time to make theses PR merged than typing |
xabbuh left a comment
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.
@lyrixx Can you change the PR title to better match what we now have here? :)
zanbaldwin commentedJan 11, 2019
Changing Also, can someone from the core team clarify which syntax Symfony components now use? |
ostrolucky commentedJan 11, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
All the concerns raised could be solved by using@javiereguiluz's suggestion edit: to clarify, I'm not implying this should submit the form. This is only shortcut for |
gharlan commentedJan 11, 2019
chalasr commentedJan 11, 2019
And have an |
ostrolucky commentedJan 12, 2019
No exception, it's not implied anywhere |
zanbaldwin commentedJan 14, 2019
Just as a minor public service announcement, I just found out it was quietly decided6 days ago that the main Symfony codebase now uses the short array syntax. |
fabpot commentedJan 14, 2019
Thank you@lyrixx. |
…) (lyrixx)This PR was squashed before being merged into the 4.3-dev branch (closes#29813).Discussion----------[FrameworkBundle] Remove ControllerTrait::isFormValid()| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#24576 (comment)| License | MIT| Doc PR |**edit**: During the first draft I made, I did not use the request stack. I finally used it to mimic other shortcut! It was a bad idea. Now there is less code, it's simpler. Love it moreCommits-------2be1987 [FrameworkBundle] Remove ControllerTrait::isFormValid()


Uh oh!
There was an error while loading.Please reload this page.
edit: During the first draft I made, I did not use the request stack. I finally used it to mimic other shortcut! It was a bad idea. Now there is less code, it's simpler. Love it more