-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@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! |
@javiereguiluz we added So let's keep thing simple here. I really prefer |
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: public function new(Request $request)
{
$task = new Task();
$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: public function new(Request $request)
{
$task = new Task();
$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! |
If the form being submitted is a condition of it being valid, then I would suggest |
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: public function new(Request $request)
{
$task = new Task();
$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 |
@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. |
What should I do? I'm a bit confused here :| |
@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. |
I think we should remove the method personally. |
I would vote to revert as well. |
Are you talking about submitted vs valid ? |
@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". |
Too much important things are hidden by this shortcut, the name does not reflect what it does. I don't expect a |
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 |
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? :)
Changing Also, can someone from the core team clarify which syntax Symfony components now use? |
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 |
And have an |
No exception, it's not implied anywhere |
Just as a minor public service announcement, I just found out it was quietly decided 6 days ago that the main Symfony codebase now uses the short array syntax. |
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 more Commits ------- 2be1987 [FrameworkBundle] Remove ControllerTrait::isFormValid()
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