Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:masterfromlyrixx:form-is-valid
Jan 14, 2019

Conversation

@lyrixx
Copy link
Member

@lyrixxlyrixx commentedJan 8, 2019
edited
Loading

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#24576 (comment)
LicenseMIT
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

yceruto and fbourigault reacted with thumbs up emoji
@javiereguiluz
Copy link
Member

@weaverryan I'd like to read your opinion about this. In the past you insisted a lot to add the$form->isSubmitted() && ... to all the doc examples to be more explicit. I think that's the right decision because code is easier to understand (otherwise newcomers can get lost:who/when/how was the form submitted !?!?)

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
Copy link
MemberAuthor

@javiereguiluz we addedisSubmitted() everywhere in the doc to fix an inconsistency in the Form Component. This is just a hack. Before the inconsistency was raised, almost nobody usedisSubmitted() and everything were fine.

So let's keep thing simple here. I really preferisFormValid(). There are no need to explain aboutisSubmitted()

@javiereguiluz
Copy link
Member

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$form->isSubmitted() ... the code is harder to understand but newcomers think:"OK, I guess the form submission will take place in this weird $form->handleRequest($request) call which I don't understand (yet)."

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!

danabrey reacted with thumbs up emoji

@mbabker
Copy link
Contributor

If the form being submitted is a condition of it being valid, then I would suggestisFormValid is perfectly fine as far as naming goes.

lyrixx reacted with thumbs up emoji

@weaverryan
Copy link
Member

weaverryan commentedJan 10, 2019
edited by lyrixx
Loading

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 withis that performs an action (an important action). And I can't really think of anything I love :/. But I'm also not sure the current/old way is a huge problem.

If anything, I tend to agree with Javier's suggestions:#29813 (comment) - orif ($this->submitForm($form, $request) && $form->isValid())

lyrixx we added isSubmitted() everywhere in the doc to fix an inconsistency in the Form Component. This is just a hack. Before the inconsistency was raised, almost nobody used isSubmitted() and everything were fine.

Yes, but before we addedisSubmitted(), there WAS stillhandleRequest(). So you could guess (even though the name isn't great) that this is the line that's probably submitting things. Removing any line that suggests the form being submitted is where things get slippery.

apfelbox, jvasseur, danabrey, and smnandre reacted with thumbs up emoji

@fabpot
Copy link
Member

@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
Copy link
MemberAuthor

What should I do? I'm a bit confused here :|

@javiereguiluz
Copy link
Member

@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
Copy link
Member

I think we should remove the method personally.

@fabpot
Copy link
Member

I would vote to revert as well.

@lyrixx
Copy link
MemberAuthor

As mentioned, controllers handling forms have two very different execution branches ... and this shortcut hides that too much at the moment.

Are you talking about submitted vs valid ?

@javiereguiluz
Copy link
Member

@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
Copy link
Member

chalasr commentedJan 10, 2019
edited
Loading

Too much important things are hidden by this shortcut, the name does not reflect what it does. I don't expect aisFormValid() method to throw if the form is submitted, nor I expect it to process submission by itself. +1 for reverting.

davidarich reacted with thumbs up emoji

@lyrixx
Copy link
MemberAuthor

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 typingif ($form->handleRequest($request)->isSubmitted()) && $form->isValid()) { 😂
So Let's revert it :)

Copy link
Member

@xabbuhxabbuh left a 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? :)

@lyrixxlyrixx changed the title[FrameworkBundle] Make the request mandatory in ControllerTrait::isFormValid()[FrameworkBundle] Remove ControllerTrait::isFormValid()Jan 11, 2019
@zanbaldwin
Copy link
Member

Changingarray() syntax to[] is probably outside the scope of this pull request.

Also, can someone from the core team clarify which syntax Symfony components now use?
Last I heard the only place the new syntax was being used was insymfony/flex and not the components 🤷‍♀️

sstok reacted with thumbs up emoji

@ostrolucky
Copy link
Contributor

ostrolucky commentedJan 11, 2019
edited
Loading

All the concerns raised could be solved by using@javiereguiluz's suggestionisFormSubmittedAndValid. Not sure why revert was chosen instead of simple rename.

edit: to clarify, I'm not implying this should submit the form. This is only shortcut forisSubmitted && isValid

@gharlan
Copy link
Contributor

Maybe just add aisSubmittedAndValid() shortcut to form instead of ControllerTrait, and without implicithandleRequest?

2019-01-11 14 59 11

vs.

2019-01-11 15 01 43

I need ~5.8s to type this instead of ~9.3s (with autocompletion in phpstorm). Don't know, if it is worth it. ;)

@chalasr
Copy link
Member

And have anisSubmitted...() throwing an exception if the form is not submitted? Sounds plain wrong to me.

@ostrolucky
Copy link
Contributor

No exception, it's not implied anywhere

@zanbaldwin
Copy link
Member

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.
Therefore the changes that@lyrixx has included in this PR are the correct way of doing it.
/cc@sstok

sstok reacted with thumbs up emoji

@fabpot
Copy link
Member

Thank you@lyrixx.

@fabpotfabpot merged commit2be1987 intosymfony:masterJan 14, 2019
fabpot added a commit that referenced this pull requestJan 14, 2019
…) (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()
@lyrixxlyrixx deleted the form-is-valid branchJanuary 14, 2019 11:21
@fabpotfabpot mentioned this pull requestMay 9, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@xabbuhxabbuhxabbuh requested changes

@stofstofstof approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

13 participants

@lyrixx@javiereguiluz@mbabker@weaverryan@fabpot@nicolas-grekas@chalasr@zanbaldwin@ostrolucky@gharlan@stof@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp