-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Form] Add example for createNamed Form #11272
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
Hi 👋 Thank you for your contribution! This should be considered a bugfix and target the The sentence Please keep in mind that we are using |
@OskarStark made the changes you proposed |
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.
Thank you, this looks good to me 👍
forms.rst
Outdated
public function newAction() | ||
{ | ||
$task = ...; | ||
$form = $this->container->get('form.factory')->createNamed('name', TaskType::class, $task); |
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.
For short, we can use the shortcut instead $this->get(...)
.
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.
Yes that’s true, do we have a “standard” in the docs?
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.
The recommended way is to inject the factory with dependency injection but that will make this example maybe to complex.
$this->container
looks in this case more clearly than $this->get
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 also think using $this->get(...)
makes sense here.
@wimme002 as long as you extend AbstractController
this service is available in the service locator:
So imho no need to inject it.
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.
Agreed!
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.
Let's then slightly clearify this code example by putting a class DefaultController extends AbstractController { }
block around the method. @wimme002 as you opened this PR, are you willing to push these 2 changes to your branch? We can then merge it. If not, just tell us and we'll take care of it!
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.
Made the requested changes
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.
We could do this change while merging
Thank you Wim! Very quick responses and a good addition! |
This PR was squashed before being merged into the 3.4 branch (closes #11272). Discussion ---------- [Form] Add example for createNamed Form The docs are not very clear where the FormFactory comes from and how to use this method <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 617621a [Form] Add example for createNamed Form
The docs are not very clear where the FormFactory comes from and how to use this method