-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Form] added prototype_data option in CollectionType #6450
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
[Form] added prototype_data option in CollectionType #6450
Conversation
HeahDude
commented
Apr 9, 2016
Q | A |
---|---|
Branch | 2.8+ |
New doc | finishes #4367 |
befaeb4
to
6f15771
Compare
|
||
**type**: ``mixed`` **default**: ``null`` | ||
|
||
Allows you to define a specific data for the prototype. Each new row added will |
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.
[...] define specific data [...]
We need a |
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
|
||
$builder->add('tags', CollectionType::class, array( | ||
'class' => \AppBundle\Entity\Tag::class, |
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 the Symfony 2.8 docs we always use a string to be compatible with PHP 5.3 and 5.4.
6f15771
to
1b5e46e
Compare
@xabbuh Thanks for the review, comments addressed. |
.. code-block:: php | ||
|
||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; |
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 use statements are useless now. :)
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.
Right, I made another commit to do that change in all examples, so you can easily revert it in 3.0+ branches. Thanks!
1b5e46e
to
2034e96
Compare
👍 |
// ... | ||
|
||
$builder->add('emails', CollectionType::class, array( | ||
$builder->add('emails', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', array( |
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.
Why the change away from the CollectionType::class
? That option (with ::class
) seems a little easier because we can use IDE auto-completion. Or have we been changing this elsewhere?
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.
@weaverryan, the discussion with @xabbuh is on the outdated diff: #6450 (comment)
Because 2.8 supports PHP < 5.5, I made a different commit for those changes so it can be reverted in 3.0.
Thanks :)
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.
@HeahDude It looks like I was mistaken here and we at some point agreed on using the class
constant even in the 2.8 docs (see http://symfony.com/doc/2.8/book/forms.html, for example). Sorry for the confusion.
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.
@xabbuh No worry, I just removed the last commit :)
2034e96
to
3c08e10
Compare
// ... | ||
|
||
$builder->add('tags', CollectionType::class, array( | ||
'class' => 'AppBundle\Entity\Tag', |
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.
@xabbuh, I intentionally didn't change this one since it's almost the same:
'AppBundle\Entity\Tag'
VS \AppBundle\Entity\Tag::class
unless we add a use statement:
use AppBundle\Entity\Tag;
// ...
'class' => Tag::class
What do you like ?
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.
Actually, I was a bit confused and I am even more confused now. Where from did you take the class
option?
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.
My bad, confusion with EntityType
! Should be entry_type
data_class
in entry_options
, I'll just remove 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.
Oh okay, but entry_type
is already set to refer to the TextType
, isn't 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.
Yes I answered too quickly and edited it.
3c08e10
to
95bda57
Compare
Ok should be good now. |
Cool 👍 |
…gilden, HeahDude) This PR was merged into the 2.8 branch. Discussion ---------- [Form] added prototype_data option in CollectionType | Q | A | |----|----| | Branch | 2.8+ | | New doc | finishes #4367 | Commits ------- 95bda57 [Form] defined default and added example CollectionType `prototype_data` option e18dc1f [Form] Document CollectionType's `prototype_data`
…Type (kgilden, HeahDude)