Skip to content

Commit

Permalink
feature symfony#5051 Rename CollectionType entry options (WouterJ)
Browse files Browse the repository at this point in the history
This PR was submitted for the 2.7 branch but it was merged into the 2.8 branch instead (closes symfony#5051).

Discussion
----------

Rename CollectionType entry options

| Q | A
| --- | ---
| Doc fix? | no
| New docs? | yes (symfony/symfony#15025)
| Applies to | 2.7+
| Fixed tickets | -

Commits
-------

1b00278 Rename CollectionType entry options
  • Loading branch information
weaverryan committed Oct 15, 2015
2 parents 622b149 + 1b00278 commit 61d904f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cookbook/form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Notice that you embed a collection of ``TagType`` forms using the
{
$builder->add('description');

$builder->add('tags', 'collection', array('type' => new TagType()));
$builder->add('tags', 'collection', array('entry_type' => new TagType()));
}

public function configureOptions(OptionsResolver $resolver)
Expand Down Expand Up @@ -285,7 +285,7 @@ add the ``allow_add`` option to your collection field::
$builder->add('description');

$builder->add('tags', 'collection', array(
'type' => new TagType(),
'entry_type' => new TagType(),
'allow_add' => true,
));
}
Expand Down
52 changes: 30 additions & 22 deletions reference/forms/types/collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ photos).
| Options | - `allow_add`_ |
| | - `allow_delete`_ |
| | - `delete_empty`_ |
| | - `options`_ |
| | - `entry_options`_ |
| | - `entry_type`_ |
| | - `prototype`_ |
| | - `prototype_name`_ |
| | - `type`_ |
+-------------+-----------------------------------------------------------------------------+
| Inherited | - `by_reference`_ |
| options | - `cascade_validation`_ |
Expand Down Expand Up @@ -53,10 +53,10 @@ to an array of email addresses. In the form, you want to expose each email
address as its own input text box::

$builder->add('emails', 'collection', array(
// each item in the array will be an "email" field
'type' => 'email',
// each entry in the array will be an "email" field
'entry_type' => 'email',
// these options are passed to each "email" type
'options' => array(
'entry_options' => array(
'required' => false,
'attr' => array('class' => 'email-box')
),
Expand Down Expand Up @@ -273,20 +273,24 @@ form you have to set this option to true. However, existing collection entries
will only be deleted if you have the allow_delete_ option enabled. Otherwise
the empty values will be kept.

options
~~~~~~~
entry_options
~~~~~~~~~~~~~

.. versionadded:: 2.7
The ``entry_options`` option was introduced in Symfony 2.7 in favor of
``options``, which is available prior to 2.7.

**type**: ``array`` **default**: ``array()``

This is the array that's passed to the form type specified in the `type`_
This is the array that's passed to the form type specified in the `entry_type`_
option. For example, if you used the :doc:`choice </reference/forms/types/choice>`
type as your `type`_ option (e.g. for a collection of drop-down menus),
type as your `entry_type`_ option (e.g. for a collection of drop-down menus),
then you'd need to at least pass the ``choices`` option to the underlying
type::

$builder->add('favorite_cities', 'collection', array(
'type' => 'choice',
'options' => array(
'entry_type' => 'choice',
'entry_options' => array(
'choices' => array(
'nashville' => 'Nashville',
'paris' => 'Paris',
Expand All @@ -296,6 +300,21 @@ type::
),
));

entry_type
~~~~~~~~~~

.. versionadded:: 2.7
The ``entry_type`` option was introduced in Symfony 2.7 in favor of
``type``, which is available prior to 2.7.

**type**: ``string`` or :class:`Symfony\\Component\\Form\\FormTypeInterface` **required**

This is the field type for each item in this collection (e.g. ``text``,
``choice``, etc). For example, if you have an array of email addresses,
you'd use the :doc:`email </reference/forms/types/email>` type. If you want
to embed a collection of some other form, create a new instance of your
form type and pass it as this option.

prototype
~~~~~~~~~

Expand Down Expand Up @@ -344,17 +363,6 @@ If you have several collections in your form, or worse, nested collections
you may want to change the placeholder so that unrelated placeholders are
not replaced with the same value.

type
~~~~

**type**: ``string`` or :class:`Symfony\\Component\\Form\\FormTypeInterface` **required**

This is the field type for each item in this collection (e.g. ``text``,
``choice``, etc). For example, if you have an array of email addresses,
you'd use the :doc:`email </reference/forms/types/email>` type. If you want
to embed a collection of some other form, create a new instance of your
form type and pass it as this option.

Inherited Options
-----------------

Expand Down

0 comments on commit 61d904f

Please sign in to comment.