From 3117df5957068bfdc0d51ddc078ab4c2958789d7 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 27 Nov 2015 17:31:28 -0500 Subject: [PATCH 1/4] Another huge batch of changes for the form type changes in 2.8 --- best_practices/forms.rst | 21 +----- book/forms.rst | 7 +- book/validation.rst | 2 +- cookbook/bundles/override.rst | 15 ++-- cookbook/controller/upload_file.rst | 5 +- cookbook/form/create_custom_field_type.rst | 69 +++++++++---------- cookbook/form/create_form_type_extension.rst | 35 +++++----- cookbook/form/dynamic_form_modification.rst | 40 +---------- cookbook/form/form_collections.rst | 31 ++++----- cookbook/form/form_customization.rst | 6 +- cookbook/form/use_empty_data.rst | 16 +++-- reference/forms/types/checkbox.rst | 5 +- reference/forms/types/choice.rst | 27 ++++++-- reference/forms/types/collection.rst | 16 +++-- reference/forms/types/entity.rst | 28 ++++++-- reference/forms/types/file.rst | 5 +- reference/forms/types/money.rst | 5 +- .../forms/types/options/button_attr.rst.inc | 5 +- .../forms/types/options/by_reference.rst.inc | 6 +- .../forms/types/options/choice_attr.rst.inc | 5 +- .../forms/types/options/choice_label.rst.inc | 10 ++- reference/forms/types/options/data.rst.inc | 5 +- .../forms/types/options/data_class.rst.inc | 5 +- .../forms/types/options/date_format.rst.inc | 5 +- .../forms/types/options/empty_data.rst.inc | 5 +- .../forms/types/options/group_by.rst.inc | 5 +- .../invalid_message_parameters.rst.inc | 2 +- .../forms/types/options/placeholder.rst.inc | 15 +++- .../types/options/preferred_choices.rst.inc | 10 ++- reference/forms/types/range.rst | 5 +- reference/forms/types/repeated.rst | 10 ++- reference/forms/types/submit.rst | 7 +- reference/forms/types/time.rst | 10 ++- 33 files changed, 252 insertions(+), 191 deletions(-) diff --git a/best_practices/forms.rst b/best_practices/forms.rst index 2df876680a1..e942a40854c 100644 --- a/best_practices/forms.rst +++ b/best_practices/forms.rst @@ -110,6 +110,7 @@ some developers configure form buttons in the controller:: use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; + use Symfony\Component\Form\Extension\Core\Type\SubmitType; use AppBundle\Entity\Post; use AppBundle\Form\PostType; @@ -121,7 +122,7 @@ some developers configure form buttons in the controller:: { $post = new Post(); $form = $this->createForm(PostType::class, $post); - $form->add('submit', 'submit', array( + $form->add('submit', SubmitType::class, array( 'label' => 'Create', 'attr' => array('class' => 'btn btn-default pull-right') )); @@ -205,21 +206,3 @@ Second, we recommend using ``$form->isSubmitted()`` in the ``if`` statement for clarity. This isn't technically needed, since ``isValid()`` first calls ``isSubmitted()``. But without this, the flow doesn't read well as it *looks* like the form is *always* processed (even on the GET request). - -Custom Form Field Types ------------------------ - -.. best-practice:: - - Add the ``app_`` prefix to your custom form field types to avoid collisions. - -Custom form field types inherit from the ``AbstractType`` class, which defines the -``getName()`` method to configure the name of that form type. These names must -be unique in the application. - -If a custom form type uses the same name as any of the Symfony's built-in form -types, it will override it. The same happens when the custom form type matches -any of the types defined by the third-party bundles installed in your application. - -Add the ``app_`` prefix to your custom form field types to avoid name collisions -that can lead to hard to debug errors. diff --git a/book/forms.rst b/book/forms.rst index 036fdc127ce..95ffabc0656 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -1005,7 +1005,7 @@ ways. If you build your form in the controller, you can use ``setAction()`` and ->setAction($this->generateUrl('target_route')) ->setMethod('GET') ->add('task', TextType::class) - ->add('dueDate', DateType::clas) + ->add('dueDate', DateType::class) ->add('save', SubmitType::class) ->getForm(); @@ -1018,7 +1018,10 @@ In :ref:`book-form-creating-form-classes` you will learn how to move the form building code into separate classes. When using an external form class in the controller, you can pass the action and method as form options:: - $form = $this->createForm(new TaskType(), $task, array( + use AppBundle\Form\Type\TaskType; + // ... + + $form = $this->createForm(TaskType::class, $task, array( 'action' => $this->generateUrl('target_route'), 'method' => 'GET', )); diff --git a/book/validation.rst b/book/validation.rst index 8856de1d304..a30ea5e0e9d 100644 --- a/book/validation.rst +++ b/book/validation.rst @@ -230,7 +230,7 @@ workflow looks like the following from inside a controller:: public function updateAction(Request $request) { $author = new Author(); - $form = $this->createForm(new AuthorType(), $author); + $form = $this->createForm(AuthorType::class, $author); $form->handleRequest($request); diff --git a/cookbook/bundles/override.rst b/cookbook/bundles/override.rst index db60e778bba..375f2678504 100644 --- a/cookbook/bundles/override.rst +++ b/cookbook/bundles/override.rst @@ -105,17 +105,16 @@ associations. Learn more about this feature and its limitations in Forms ----- -In order to override a form type, it has to be registered as a service (meaning -it is tagged as ``form.type``). You can then override it as you would override any -service as explained in `Services & Configuration`_. This, of course, will only -work if the type is referred to by its alias rather than being instantiated, -e.g.:: +As of Symfony 2.8, form types are referred to by their fully-qualified class name:: - $builder->add('name', 'custom_type'); + $builder->add('name', CustomType::class); -rather than:: +This means that you cannot override this by creating a sub-class of ``CustomType`` +and registering it as a service, and tagging it with ``form.type`` (you *could* +do this in earlier version). - $builder->add('name', new CustomType()); +Instead, you should use a "form type extension" to modify the existing form type. +For more information, see :doc:`/cookbook/form/create_form_type_extension`. .. _override-validation: diff --git a/cookbook/controller/upload_file.rst b/cookbook/controller/upload_file.rst index 065b4bbaf0a..43cb18a4d5f 100644 --- a/cookbook/controller/upload_file.rst +++ b/cookbook/controller/upload_file.rst @@ -57,6 +57,7 @@ Then, add a new ``brochure`` field to the form that manages the ``Product`` enti use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; + use Symfony\Component\Form\Extension\Core\Type\FileType; class ProductType extends AbstractType { @@ -64,7 +65,7 @@ Then, add a new ``brochure`` field to the form that manages the ``Product`` enti { $builder // ... - ->add('brochure', 'file', array('label' => 'Brochure (PDF file)')) + ->add('brochure', FileType::class, array('label' => 'Brochure (PDF file)')) // ... ; } @@ -116,7 +117,7 @@ Finally, you need to update the code of the controller that handles the form:: public function newAction(Request $request) { $product = new Product(); - $form = $this->createForm(new ProductType(), $product); + $form = $this->createForm(ProductType::class, $product); $form->handleRequest($request); if ($form->isValid()) { diff --git a/cookbook/form/create_custom_field_type.rst b/cookbook/form/create_custom_field_type.rst index ab933f6e8ea..b95e1d70683 100644 --- a/cookbook/form/create_custom_field_type.rst +++ b/cookbook/form/create_custom_field_type.rst @@ -25,6 +25,7 @@ for form fields, which is ``\Form\Type``. Make sure the field extend use Symfony\Component\Form\AbstractType; use Symfony\Component\OptionsResolver\OptionsResolver; + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; class GenderType extends AbstractType { @@ -40,12 +41,7 @@ for form fields, which is ``\Form\Type``. Make sure the field extend public function getParent() { - return 'choice'; - } - - public function getName() - { - return 'gender'; + return ChoiceType::class; } } @@ -54,8 +50,12 @@ for form fields, which is ``\Form\Type``. Make sure the field extend The location of this file is not important - the ``Form\Type`` directory is just a convention. +.. versionadded:: 2.8 + In 2.8, the ``getName()`` method was removed. Now, fields are always referred + to by their fully-qualified class name. + Here, the return value of the ``getParent`` function indicates that you're -extending the ``choice`` field type. This means that, by default, you inherit +extending the ``ChoiceType`` field. This means that, by default, you inherit all of the logic and rendering of that field type. To see some of the logic, check out the `ChoiceType`_ class. There are three methods that are particularly important: @@ -89,10 +89,6 @@ important: Also, if you need to modify the "view" of any of your child types from your parent type, use the ``finishView()`` method. -The ``getName()`` method returns an identifier which should be unique in -your application. This is used in various places, such as when customizing -how your form type will be rendered. - The goal of this field was to extend the choice type to enable selection of a gender. This is achieved by fixing the ``choices`` to a list of possible genders. @@ -100,13 +96,19 @@ genders. Creating a Template for the Field --------------------------------- -Each field type is rendered by a template fragment, which is determined in -part by the value of your ``getName()`` method. For more information, see +Each field type is rendered by a template fragment, which is determined in part by +the class name of your type. For more information, see :ref:`cookbook-form-customization-form-themes`. -In this case, since the parent field is ``choice``, you don't *need* to do -any work as the custom field type will automatically be rendered like a ``choice`` -type. But for the sake of this example, suppose that when your field is "expanded" +.. note:: + + The first part of the prefix (e.g. ``gender``) comes from the class name + (``GenderType`` -> ``gender``). This can be controlled by overriding ``getBlockPrefix()`` + in ``GenderType``. + +In this case, since the parent field is ``ChoiceType``, you don't *need* to do +any work as the custom field type will automatically be rendered like a ``ChoiceType``. +But for the sake of this example, suppose that when your field is "expanded" (i.e. radio buttons or checkboxes, instead of a select field), you want to always render it in a ``ul`` element. In your form theme template (see above link for details), create a ``gender_widget`` block to handle this: @@ -154,7 +156,7 @@ link for details), create a ``gender_widget`` block to handle this: .. note:: Make sure the correct widget prefix is used. In this example the name should - be ``gender_widget``, according to the value returned by ``getName``. + be ``gender_widget`` (see :ref:`cookbook-form-customization-form-themes`). Further, the main config file should point to the custom form template so that it's used when rendering all forms. @@ -241,18 +243,19 @@ new instance of the type in one of your forms:: use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; + use AppBundle\Form\Type\GenderType; class AuthorType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('gender_code', new GenderType(), array( + $builder->add('gender_code', GenderType::class, array( 'placeholder' => 'Choose a gender', )); } } -But this only works because the ``GenderType()`` is very simple. What if +But this only works because the ``GenderType`` is very simple. What if the gender codes were stored in configuration or in a database? The next section explains how more complex field types solve this problem. @@ -311,14 +314,14 @@ the ``genders`` parameter value as the first argument to its to-be-created arguments: - "%genders%" tags: - - { name: form.type, alias: gender } + - { name: form.type } .. code-block:: xml %genders% - + .. code-block:: php @@ -331,9 +334,7 @@ the ``genders`` parameter value as the first argument to its to-be-created 'AppBundle\Form\Type\GenderType', array('%genders%') )) - ->addTag('form.type', array( - 'alias' => 'gender', - )) + ->addTag('form.type') ; .. tip:: @@ -341,10 +342,8 @@ the ``genders`` parameter value as the first argument to its to-be-created Make sure the services file is being imported. See :ref:`service-container-imports-directive` for details. -Be sure that the ``alias`` attribute of the tag corresponds with the value -returned by the ``getName`` method defined earlier. You'll see the importance -of this in a moment when you use the custom field type. But first, add a ``__construct`` -method to ``GenderType``, which receives the gender configuration:: +First, add a ``__construct`` method to ``GenderType``, which receives the gender +configuration:: // src/AppBundle/Form/Type/GenderType.php namespace AppBundle\Form\Type; @@ -374,28 +373,28 @@ method to ``GenderType``, which receives the gender configuration:: } Great! The ``GenderType`` is now fueled by the configuration parameters and -registered as a service. Additionally, because you used the ``form.type`` alias in its -configuration, using the field is now much easier:: +registered as a service. Because you used the ``form.type`` alias in its configuration, +your service will be used instead of creating a *new* ``GenderType``. In other words, +your controller *does not need to change*, it still looks like this:: // src/AppBundle/Form/Type/AuthorType.php namespace AppBundle\Form\Type; + use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; - - // ... + use AppBundle\Form\Type\GenderType; class AuthorType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('gender_code', 'gender', array( + $builder->add('gender_code', GenderType::class, array( 'placeholder' => 'Choose a gender', )); } } -Notice that instead of instantiating a new instance, you can just refer to -it by the alias used in your service configuration, ``gender``. Have fun! +Have fun! .. _`ChoiceType`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php .. _`FieldType`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php diff --git a/cookbook/form/create_form_type_extension.rst b/cookbook/form/create_form_type_extension.rst index 85a786066f4..11009d5922f 100644 --- a/cookbook/form/create_form_type_extension.rst +++ b/cookbook/form/create_form_type_extension.rst @@ -15,7 +15,7 @@ extensions come in. Form type extensions have 2 main use-cases: #. You want to add a **specific feature to a single type** (such - as adding a "download" feature to the "file" field type); + as adding a "download" feature to the ``FileType`` field type); #. You want to add a **generic feature to several types** (such as adding a "help" text to every "input text"-like type). @@ -51,6 +51,7 @@ class. In most cases, it's easier to extend the abstract class:: namespace AppBundle\Form\Extension; use Symfony\Component\Form\AbstractTypeExtension; + use Symfony\Component\Form\Extension\Core\Type\FileType; class ImageTypeExtension extends AbstractTypeExtension { @@ -61,7 +62,7 @@ class. In most cases, it's easier to extend the abstract class:: */ public function getExtendedType() { - return 'file'; + return FileType::class; } } @@ -105,14 +106,14 @@ tag: app.image_type_extension: class: AppBundle\Form\Extension\ImageTypeExtension tags: - - { name: form.type_extension, alias: file } + - { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\FileType } .. code-block:: xml - + .. code-block:: php @@ -122,11 +123,15 @@ tag: 'app.image_type_extension', 'AppBundle\Form\Extension\ImageTypeExtension' ) - ->addTag('form.type_extension', array('alias' => 'file')); + ->addTag('form.type_extension', array('extended_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType')); + +.. versionadded:: 2.8 + The ``extended_type`` option is new in Symfony 2.8. Before, the option was + called ``alias``. -The ``alias`` key of the tag is the type of field that this extension should -be applied to. In your case, as you want to extend the ``file`` field type, -you will use ``file`` as an alias. +The ``extended_type`` key of the tag is the type of field that this extension should +be applied to. In your case, as you want to extend the ``Symfony\Component\Form\Extension\Core\Type\FileType`` +field type, you will use that as the ``extended_type``. Adding the extension Business Logic ----------------------------------- @@ -175,14 +180,14 @@ database):: } Your form type extension class will need to do two things in order to extend -the ``file`` form type: +the ``FileType::class`` form type: #. Override the ``configureOptions`` method in order to add an ``image_path`` option; #. Override the ``buildForm`` and ``buildView`` methods in order to pass the image URL to the view. -The logic is the following: when adding a form field of type ``file``, +The logic is the following: when adding a form field of type ``FileType::class``, you will be able to specify a new option: ``image_path``. This option will tell the file field how to get the actual image URL in order to display it in the view:: @@ -195,6 +200,7 @@ it in the view:: use Symfony\Component\Form\FormInterface; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\OptionsResolver\OptionsResolver; + use Symfony\Component\Form\Extension\Core\Type\FileType; class ImageTypeExtension extends AbstractTypeExtension { @@ -205,7 +211,7 @@ it in the view:: */ public function getExtendedType() { - return 'file'; + return FileType::class; } /** @@ -291,7 +297,7 @@ Specifically, you need to override the ``file_widget`` block: Using the Form Type Extension ----------------------------- -From now on, when adding a field of type ``file`` in your form, you can +From now on, when adding a field of type ``FileType::class`` in your form, you can specify an ``image_path`` option that will be used to display an image next to the file field. For example:: @@ -311,11 +317,6 @@ next to the file field. For example:: ->add('name', TextType::class) ->add('file', FileType::class, array('image_path' => 'webPath')); } - - public function getName() - { - return 'media'; - } } When displaying the form, if the underlying model has already been associated diff --git a/cookbook/form/dynamic_form_modification.rst b/cookbook/form/dynamic_form_modification.rst index 085b34beb7d..6483ed73532 100644 --- a/cookbook/form/dynamic_form_modification.rst +++ b/cookbook/form/dynamic_form_modification.rst @@ -346,39 +346,8 @@ and fill in the listener logic:: Using the Form ~~~~~~~~~~~~~~ -Our form is now ready to use and there are two possible ways to use it inside -of a controller: - -a) create it manually and remember to pass the token storage to it; - -or - -b) define it as a service. - -a) Creating the Form manually -............................. - -This is very simple, and is probably the better approach unless you're using -your new form type in many places or embedding it into other forms:: - - class FriendMessageController extends Controller - { - public function newAction(Request $request) - { - $tokenStorage = $this->container->get('security.token_storage'); - $form = $this->createForm( - new FriendMessageFormType($tokenStorage) - ); - - // ... - } - } - -b) Defining the Form as a Service -................................. - -To define your form as a service, just create a normal service and then tag -it with :ref:`dic-tags-form-type`. +Our form is now ready to use. But first, because it has a ``__construct()`` method, +you need to register it as a service and tag it with :ref:`form.type `: .. configuration-block:: @@ -413,11 +382,6 @@ it with :ref:`dic-tags-form-type`. array('security.token_storage') ); -If you wish to create it from within a service that has access to the form factory, -you then use:: - - $form = $formFactory->create('friend_message'); - In a controller that extends the :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller` class, you can simply call:: diff --git a/cookbook/form/form_collections.rst b/cookbook/form/form_collections.rst index e186f642f17..903ef4d3a37 100644 --- a/cookbook/form/form_collections.rst +++ b/cookbook/form/form_collections.rst @@ -99,11 +99,6 @@ Then, create a form class so that a ``Tag`` object can be modified by the user:: 'data_class' => 'AppBundle\Entity\Tag', )); } - - public function getName() - { - return 'tag'; - } } With this, you have enough to render a tag form by itself. But since the end @@ -119,6 +114,7 @@ Notice that you embed a collection of ``TagType`` forms using the use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; + use Symfony\Component\Form\Extension\Core\Type\CollectionType; class TaskType extends AbstractType { @@ -126,7 +122,9 @@ Notice that you embed a collection of ``TagType`` forms using the { $builder->add('description'); - $builder->add('tags', 'collection', array('entry_type' => new TagType())); + $builder->add('tags', CollectionType::class, array( + 'entry_type' => TagType::class + )); } public function configureOptions(OptionsResolver $resolver) @@ -135,14 +133,9 @@ Notice that you embed a collection of ``TagType`` forms using the 'data_class' => 'AppBundle\Entity\Task', )); } - - public function getName() - { - return 'task'; - } } -In your controller, you'll now initialize a new instance of ``TaskType``:: +In your controller, you'll create a new form from the ``TaskType``: // src/AppBundle/Controller/TaskController.php namespace AppBundle\Controller; @@ -169,7 +162,7 @@ In your controller, you'll now initialize a new instance of ``TaskType``:: $task->getTags()->add($tag2); // end dummy code - $form = $this->createForm(new TaskType(), $task); + $form = $this->createForm(TaskType::class, $task); $form->handleRequest($request); @@ -284,8 +277,8 @@ add the ``allow_add`` option to your collection field:: { $builder->add('description'); - $builder->add('tags', 'collection', array( - 'entry_type' => new TagType(), + $builder->add('tags', CollectionType::class, array( + 'entry_type' => TagType::class, 'allow_add' => true, )); } @@ -453,7 +446,7 @@ Next, add a ``by_reference`` option to the ``tags`` field and set it to ``false` { // ... - $builder->add('tags', 'collection', array( + $builder->add('tags', CollectionType::class, array( // ... 'by_reference' => false, )); @@ -569,7 +562,7 @@ you will learn about next!). .. _cookbook-form-collections-remove: Allowing Tags to be Removed ----------------------------- +--------------------------- The next step is to allow the deletion of a particular item in the collection. The solution is similar to allowing tags to be added. @@ -583,7 +576,7 @@ Start by adding the ``allow_delete`` option in the form Type:: { // ... - $builder->add('tags', 'collection', array( + $builder->add('tags', CollectionType::class, array( // ... 'allow_delete' => true, )); @@ -696,7 +689,7 @@ the relationship between the removed ``Tag`` and ``Task`` object. $originalTags->add($tag); } - $editForm = $this->createForm(new TaskType(), $task); + $editForm = $this->createForm(new TaskType::class, $task); $editForm->handleRequest($request); diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index b90f22455db..025297bee32 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -211,6 +211,9 @@ this folder. In this example, the customized fragment name is ``integer_widget`` because you want to override the HTML ``widget`` for all ``integer`` field types. If you need to customize ``textarea`` fields, you would customize ``textarea_widget``. + + The ``integer`` part comes from the class name: ``IntegerType`` becomes ``integer``, + based on a standard. As you can see, the fragment name is a combination of the field type and which part of the field is being rendered (e.g. ``widget``, ``label``, @@ -698,12 +701,13 @@ field whose *id* is ``product_name`` (and name is ``product[name]``). form type:: use Symfony\Component\Form\FormBuilderInterface; + use Symfony\Component\Form\Extension\Core\Type\TextType; public function buildForm(FormBuilderInterface $builder, array $options) { // ... - $builder->add('name', 'text', array( + $builder->add('name', TextType::class, array( 'block_name' => 'custom_name', )); } diff --git a/cookbook/form/use_empty_data.rst b/cookbook/form/use_empty_data.rst index 342341e5b7a..79026a573f0 100644 --- a/cookbook/form/use_empty_data.rst +++ b/cookbook/form/use_empty_data.rst @@ -15,11 +15,11 @@ your form. For example:: // $blog is passed in as the data, so the empty_data // option is not needed - $form = $this->createForm(new BlogType(), $blog); + $form = $this->createForm(BlogType::class, $blog); // no data is passed in, so empty_data is // used to get the "starting data" - $form = $this->createForm(new BlogType()); + $form = $this->createForm(BlogType::class); } By default, ``empty_data`` is set to ``null``. Or, if you have specified @@ -61,10 +61,14 @@ that constructor with no arguments:: } } -You can instantiate your class however you want. In this example, we pass -some dependency into the ``BlogType`` when we instantiate it, then use that -to instantiate the ``Blog`` class. The point is, you can set ``empty_data`` -to the exact "new" object that you want to use. +You can instantiate your class however you want. In this example, you pass +some dependency into the ``BlogType`` then use that to instantiate the ``Blog`` class. +The point is, you can set ``empty_data`` to the exact "new" object that you want to use. + +.. tip:: + + In order to pass arguments to the ``BlogType`` constructor, you'll need to + :ref:`register it as a service and tag with form.type `. Option 2: Provide a Closure --------------------------- diff --git a/reference/forms/types/checkbox.rst b/reference/forms/types/checkbox.rst index 3b45e55c582..5f774a3498e 100644 --- a/reference/forms/types/checkbox.rst +++ b/reference/forms/types/checkbox.rst @@ -36,7 +36,10 @@ Example Usage .. code-block:: php - $builder->add('public', 'checkbox', array( + use Symfony\Component\Form\Extension\Core\Type\CheckboxType; + // ... + + $builder->add('public', CheckboxType::class, array( 'label' => 'Show this entry publicly?', 'required' => false, )); diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index 346e7ef7a08..1a9c101fbcf 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -52,7 +52,10 @@ Example Usage The easiest way to use this field is to specify the choices directly via the ``choices`` option:: - $builder->add('isAttending', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('isAttending', ChoiceType::class, array( 'choices' => array( 'Maybe' => null, 'Yes' => true, @@ -87,7 +90,10 @@ This field has a *lot* of options and most control how the field is displayed. I this example, the underlying data is some ``Category`` object that has a ``getName()`` method:: - $builder->add('category', 'choice', [ + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('category', ChoiceType::class, [ 'choices' => [ new Category('Cat1'), new Category('Cat2'), @@ -132,7 +138,10 @@ Grouping Options You can easily "group" options in a select by passing a multi-dimensional choices array:: - $builder->add('stockStatus', 'choice', [ + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('stockStatus', ChoiceType::class, [ 'choices' => [ 'Main Statuses' => [ 'Yes' => 'stock_yes', @@ -163,7 +172,10 @@ This is the most basic way to specify the choices that should be used by this field. The ``choices`` option is an array, where the array key is the item's label and the array value is the item's value:: - $builder->add('inStock', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('inStock', ChoiceType::class, array( 'choices' => array('In Stock' => true, 'Out of Stock' => false), // always include this 'choices_as_values' => true, @@ -195,7 +207,7 @@ to the user. * Since 2.7:: - $builder->add('gender', 'choice', array( + $builder->add('gender', ChoiceType::class, array( // Shows "Male" to the user, returns "m" when selected 'choices' => array('Male' => 'm', 'Female' => 'f'), 'choices_as_values' => true, @@ -206,7 +218,7 @@ type behaves as if it were set to true: * Default for 3.0:: - $builder->add('gender', 'choice', array( + $builder->add('gender', ChoiceType::class, array( 'choices' => array('Male' => 'm', 'Female' => 'f'), )); @@ -263,9 +275,10 @@ With this option you can also allow float values to be selected as data. For example:: use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList; + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; // ... - $builder->add('status', 'choice', array( + $builder->add('status', ChoiceType::class, array( 'choice_list' => new ChoiceList( array(1, 0.5, 0.1), array('Full', 'Half', 'Almost empty') diff --git a/reference/forms/types/collection.rst b/reference/forms/types/collection.rst index 8c322eaea0e..3dfdddfe435 100644 --- a/reference/forms/types/collection.rst +++ b/reference/forms/types/collection.rst @@ -52,9 +52,13 @@ in a form. For example, suppose you have an ``emails`` field that corresponds 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( + use Symfony\Component\Form\Extension\Core\Type\CollectionType; + use Symfony\Component\Form\Extension\Core\Type\EmailType; + // ... + + $builder->add('emails', CollectionType::class, array( // each entry in the array will be an "email" field - 'entry_type' => 'email', + 'entry_type' => EmailType::class, // these options are passed to each "email" type 'entry_options' => array( 'required' => false, @@ -288,8 +292,12 @@ 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( - 'entry_type' => 'choice', + use Symfony\Component\Form\Extension\Core\Type\CollectionType; + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('favorite_cities', CollectionType::class, array( + 'entry_type' => ChoiceType::class, 'entry_options' => array( 'choices' => array( 'nashville' => 'Nashville', diff --git a/reference/forms/types/entity.rst b/reference/forms/types/entity.rst index da48a29b788..a0487477029 100644 --- a/reference/forms/types/entity.rst +++ b/reference/forms/types/entity.rst @@ -52,7 +52,10 @@ Basic Usage The ``entity`` type has just one required option: the entity which should be listed inside the choice field:: - $builder->add('users', 'entity', array( + use Symfony\Bridge\Doctrine\Form\Type\EntityType; + // ... + + $builder->add('users', EntityType::class, array( 'class' => 'AcmeHelloBundle:User', 'choice_label' => 'username', )); @@ -71,9 +74,10 @@ If you need to specify a custom query to use when fetching the entities the ``query_builder`` option. The easiest way to use the option is as follows:: use Doctrine\ORM\EntityRepository; + use Symfony\Bridge\Doctrine\Form\Type\EntityType; // ... - $builder->add('users', 'entity', array( + $builder->add('users', EntityType::class, array( 'class' => 'AcmeHelloBundle:User', 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('u') @@ -92,7 +96,10 @@ For example, if you have a ``$group`` variable (passed into your form perhaps as a form option) and ``getUsers`` returns a collection of ``User`` entities, then you can supply the ``choices`` option directly:: - $builder->add('users', 'entity', array( + use Symfony\Bridge\Doctrine\Form\Type\EntityType; + // ... + + $builder->add('users', EntityType::class, array( 'class' => 'AcmeHelloBundle:User', 'choices' => $group->getUsers(), )); @@ -123,7 +130,10 @@ choice_label This is the property that should be used for displaying the entities as text in the HTML element:: - $builder->add('category', 'entity', array( + use Symfony\Bridge\Doctrine\Form\Type\EntityType; + // ... + + $builder->add('category', EntityType::class, array( 'class' => 'AppBundle:Category', 'choice_label' => 'displayName', )); @@ -131,7 +141,10 @@ the HTML element:: If left blank, the entity object will be cast to a string and so must have a ``__toString()`` method. You can also pass a callback function for more control:: - $builder->add('category', 'entity', array( + use Symfony\Bridge\Doctrine\Form\Type\EntityType; + // ... + + $builder->add('category', EntityType::class, array( 'class' => 'AppBundle:Category', 'choice_label' => function ($category) { return $category->getDisplayName(); @@ -150,7 +163,10 @@ more detais, see the main :ref:`choice_label ` docu For example, if the translations property is actually an associative array of objects, each with a name property, then you could do this:: - $builder->add('gender', 'entity', array( + use Symfony\Bridge\Doctrine\Form\Type\EntityType; + // ... + + $builder->add('gender', EntityType::class, array( 'class' => 'MyBundle:Gender', 'choice_label' => 'translations[en].name', )); diff --git a/reference/forms/types/file.rst b/reference/forms/types/file.rst index 0a1e6f534f4..b31b72a3f18 100644 --- a/reference/forms/types/file.rst +++ b/reference/forms/types/file.rst @@ -34,7 +34,10 @@ Basic Usage Say you have this form definition:: - $builder->add('attachment', 'file'); + use Symfony\Component\Form\Extension\Core\Type\FileType; + // ... + + $builder->add('attachment', FileType::class); When the form is submitted, the ``attachment`` field will be an instance of :class:`Symfony\\Component\\HttpFoundation\\File\\UploadedFile`. It can diff --git a/reference/forms/types/money.rst b/reference/forms/types/money.rst index cec92232cea..a9683f02abc 100644 --- a/reference/forms/types/money.rst +++ b/reference/forms/types/money.rst @@ -65,7 +65,10 @@ If, for some reason, you need to divide your starting value by a number before rendering it to the user, you can use the ``divisor`` option. For example:: - $builder->add('price', 'money', array( + use Symfony\Component\Form\Extension\Core\Type\FileType; + // ... + + $builder->add('price', MoneyType::class, array( 'divisor' => 100, )); diff --git a/reference/forms/types/options/button_attr.rst.inc b/reference/forms/types/options/button_attr.rst.inc index 20265677042..93f70017d7e 100644 --- a/reference/forms/types/options/button_attr.rst.inc +++ b/reference/forms/types/options/button_attr.rst.inc @@ -7,6 +7,9 @@ If you want to add extra attributes to the HTML representation of the button, you can use ``attr`` option. It's an associative array with HTML attribute as a key. This can be useful when you need to set a custom class for the button:: - $builder->add('save', 'button', array( + use Symfony\Component\Form\Extension\Core\Type\ButtonType; + // ... + + $builder->add('save', ButtonType::class, array( 'attr' => array('class' => 'save'), )); diff --git a/reference/forms/types/options/by_reference.rst.inc b/reference/forms/types/options/by_reference.rst.inc index 1023e625cd9..6055ff8508b 100644 --- a/reference/forms/types/options/by_reference.rst.inc +++ b/reference/forms/types/options/by_reference.rst.inc @@ -10,9 +10,13 @@ called in all cases. To explain this further, here's a simple example:: + use Symfony\Component\Form\Extension\Core\Type\TextType; + use Symfony\Component\Form\Extension\Core\Type\EmailType; + // ... + $builder = $this->createFormBuilder($article); $builder - ->add('title', 'text') + ->add('title', TextType::class) ->add( $builder->create('author', 'form', array('by_reference' => ?)) ->add('name', TextType::class) diff --git a/reference/forms/types/options/choice_attr.rst.inc b/reference/forms/types/options/choice_attr.rst.inc index 4b4d8f187ac..4b31fc3deb8 100644 --- a/reference/forms/types/options/choice_attr.rst.inc +++ b/reference/forms/types/options/choice_attr.rst.inc @@ -12,7 +12,10 @@ of attributes (if they are the same for each choice), a callable or a property p If an array, the keys of the ``choices`` array must be used as keys:: - $builder->add('attending', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('attending', ChoiceType::class, array( 'choices' => array( 'Yes' => true, 'No' => false, diff --git a/reference/forms/types/options/choice_label.rst.inc b/reference/forms/types/options/choice_label.rst.inc index d2ebb176906..a27f1ece7f6 100644 --- a/reference/forms/types/options/choice_label.rst.inc +++ b/reference/forms/types/options/choice_label.rst.inc @@ -10,7 +10,10 @@ Normally, the array key of each item in the ``choices`` option is used as the text that's shown to the user. The ``choice_label`` option allows you to take more control:: - $builder->add('attending', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('attending', ChoiceType::class, array( 'choices' => array( 'yes' => true, 'no' => false, @@ -39,7 +42,10 @@ If your choice values are objects, then ``choice_label`` can also be a :ref:`property path `. Imagine you have some ``Status`` class with a ``getDisplayName()`` method:: - $builder->add('attending', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('attending', ChoiceType::class, array( 'choices' => array( new Status(Status::YES), new Status(Status::NO), diff --git a/reference/forms/types/options/data.rst.inc b/reference/forms/types/options/data.rst.inc index c9bf76424c5..63ca91cbf5c 100644 --- a/reference/forms/types/options/data.rst.inc +++ b/reference/forms/types/options/data.rst.inc @@ -8,7 +8,10 @@ corresponding property of the form's domain object (if an object is bound to the form). If you want to override the initial value for the form or just an individual field, you can set it in the data option:: - $builder->add('token', 'hidden', array( + use Symfony\Component\Form\Extension\Core\Type\HiddenType; + // ... + + $builder->add('token', HiddenType::class, array( 'data' => 'abcdef', )); diff --git a/reference/forms/types/options/data_class.rst.inc b/reference/forms/types/options/data_class.rst.inc index 991e68635ea..0d81c0659e4 100644 --- a/reference/forms/types/options/data_class.rst.inc +++ b/reference/forms/types/options/data_class.rst.inc @@ -8,6 +8,9 @@ form, so you can use it for any form field type which requires an object. .. code-block:: php - $builder->add('media', 'sonata_media_type', array( + use AppBundle\Form\MediaType; + // ... + + $builder->add('media', MediaType::class, array( 'data_class' => 'Acme\DemoBundle\Entity\Media', )); diff --git a/reference/forms/types/options/date_format.rst.inc b/reference/forms/types/options/date_format.rst.inc index 62152ac48ac..283a6c13d87 100644 --- a/reference/forms/types/options/date_format.rst.inc +++ b/reference/forms/types/options/date_format.rst.inc @@ -13,7 +13,10 @@ override it by passing the format as a string. For more information on valid formats, see `Date/Time Format Syntax`_:: - $builder->add('date_created', 'date', array( + use Symfony\Component\Form\Extension\Core\Type\DateType; + // ... + + $builder->add('date_created', DateType::class, array( 'widget' => 'single_text', // this is actually the default format for single_text 'format' => 'yyyy-MM-dd', diff --git a/reference/forms/types/options/empty_data.rst.inc b/reference/forms/types/options/empty_data.rst.inc index e1baeb1e7ce..02eb8d12d4c 100644 --- a/reference/forms/types/options/empty_data.rst.inc +++ b/reference/forms/types/options/empty_data.rst.inc @@ -16,7 +16,10 @@ But you can customize this to your needs. For example, if you want the ``gender`` choice field to be explicitly set to ``null`` when no value is selected, you can do it like this:: - $builder->add('gender', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('gender', ChoiceType::class, array( 'choices' => array( 'm' => 'Male', 'f' => 'Female' diff --git a/reference/forms/types/options/group_by.rst.inc b/reference/forms/types/options/group_by.rst.inc index 9147a0a09bf..4492c3e5dd9 100644 --- a/reference/forms/types/options/group_by.rst.inc +++ b/reference/forms/types/options/group_by.rst.inc @@ -15,7 +15,10 @@ a bit more flexibility. Take the following example:: - $builder->add('publishAt', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('publishAt', ChoiceType::class, array( 'choices' => array( 'now' => new \DateTime('now'), 'tomorrow' => new \DateTime('+1 day'), diff --git a/reference/forms/types/options/invalid_message_parameters.rst.inc b/reference/forms/types/options/invalid_message_parameters.rst.inc index 72a327351a4..b877f04bb72 100644 --- a/reference/forms/types/options/invalid_message_parameters.rst.inc +++ b/reference/forms/types/options/invalid_message_parameters.rst.inc @@ -7,7 +7,7 @@ When setting the ``invalid_message`` option, you may need to include some variables in the string. This can be done by adding placeholders to that option and including the variables in this option:: - $builder->add('some_field', 'some_type', array( + $builder->add('some_field', SomeFormType::class, array( // ... 'invalid_message' => 'You entered an invalid value, it should include %num% letters', 'invalid_message_parameters' => array('%num%' => 6), diff --git a/reference/forms/types/options/placeholder.rst.inc b/reference/forms/types/options/placeholder.rst.inc index afb649bdd58..12d20b00f3a 100644 --- a/reference/forms/types/options/placeholder.rst.inc +++ b/reference/forms/types/options/placeholder.rst.inc @@ -17,13 +17,19 @@ applies if the ``multiple`` option is set to false. * Add an empty value with "Choose an option" as the text:: - $builder->add('states', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('states', ChoiceType::class, array( 'placeholder' => 'Choose an option', )); * Guarantee that no "empty" value option is displayed:: - $builder->add('states', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('states', ChoiceType::class, array( 'placeholder' => false, )); @@ -31,7 +37,10 @@ If you leave the ``placeholder`` option unset, then a blank (with no text) option will automatically be added if and only if the ``required`` option is false:: + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + // a blank (with no text) option will be added - $builder->add('states', 'choice', array( + $builder->add('states', ChoiceType::class, array( 'required' => false, )); diff --git a/reference/forms/types/options/preferred_choices.rst.inc b/reference/forms/types/options/preferred_choices.rst.inc index e9b0f54ea8f..feee7351ead 100644 --- a/reference/forms/types/options/preferred_choices.rst.inc +++ b/reference/forms/types/options/preferred_choices.rst.inc @@ -7,7 +7,10 @@ This option allows you to move certain choices to the top of your list with a vi separator between them and the rest of the options. If you have a form of languages, you can list the most popular on top, like Bork Bork and Pirate:: - $builder->add('language', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('language', ChoiceType::class, array( 'choices' => array( 'English' => 'en', 'Spanish' => 'es', @@ -24,7 +27,10 @@ you can list the most popular on top, like Bork Bork and Pirate:: This options can also be a callback function to give you more flexibility. This might be especially useful if your values are objects:: - $builder->add('publishAt', 'choice', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('publishAt', ChoiceType::class, array( 'choices' => array( 'now' => new \DateTime('now'), 'tomorrow' => new \DateTime('+1 day'), diff --git a/reference/forms/types/range.rst b/reference/forms/types/range.rst index 31795c809d1..0a1e8bb855a 100644 --- a/reference/forms/types/range.rst +++ b/reference/forms/types/range.rst @@ -32,7 +32,10 @@ Basic Usage .. code-block:: php - $builder->add('name', 'range', array( + use Symfony\Component\Form\Extension\Core\Type\RangeType; + // ... + + $builder->add('name', RangeType::class, array( 'attr' => array( 'min' => 5, 'max' => 50 diff --git a/reference/forms/types/repeated.rst b/reference/forms/types/repeated.rst index fd38fe4d191..b091cb33fb2 100644 --- a/reference/forms/types/repeated.rst +++ b/reference/forms/types/repeated.rst @@ -38,7 +38,10 @@ Example Usage .. code-block:: php - $builder->add('password', 'repeated', array( + use Symfony\Component\Form\Extension\Core\Type\RepeatedType; + // ... + + $builder->add('password', RepeatedType::class, array( 'type' => 'password', 'invalid_message' => 'The password fields must match.', 'options' => array('attr' => array('class' => 'password-field')), @@ -130,7 +133,10 @@ Additional options (will be merged into `options`_ below) that should be passed *only* to the first field. This is especially useful for customizing the label:: - $builder->add('password', 'repeated', array( + use Symfony\Component\Form\Extension\Core\Type\RepeatedType; + // ... + + $builder->add('password', RepeatedType::class, array( 'first_options' => array('label' => 'Password'), 'second_options' => array('label' => 'Repeat Password'), )); diff --git a/reference/forms/types/submit.rst b/reference/forms/types/submit.rst index 9d8c015a8d8..e8722f8dd0b 100644 --- a/reference/forms/types/submit.rst +++ b/reference/forms/types/submit.rst @@ -56,11 +56,14 @@ When your form contains multiple submit buttons, you can change the validation group based on the button which was used to submit the form. Imagine a registration form wizard with buttons to go to the previous or the next step:: + use Symfony\Component\Form\Extension\Core\Type\SubmitType; + // ... + $form = $this->createFormBuilder($user) - ->add('previousStep', 'submit', array( + ->add('previousStep', SubmitType::class, array( 'validation_groups' => false, )) - ->add('nextStep', 'submit', array( + ->add('nextStep', SubmitType::class, array( 'validation_groups' => array('Registration'), )) ->getForm(); diff --git a/reference/forms/types/time.rst b/reference/forms/types/time.rst index bfbaa7e3428..e3a4b405a5e 100644 --- a/reference/forms/types/time.rst +++ b/reference/forms/types/time.rst @@ -56,7 +56,10 @@ Suppose that you have a ``startTime`` field whose underlying time data is a ``DateTime`` object. The following configures the ``time`` type for that field as two different choice fields:: - $builder->add('startTime', 'time', array( + use Symfony\Component\Form\Extension\Core\Type\TimeType; + // ... + + $builder->add('startTime', TimeType::class, array( 'input' => 'datetime', 'widget' => 'choice', )); @@ -65,7 +68,10 @@ The ``input`` option *must* be changed to match the type of the underlying date data. For example, if the ``startTime`` field's data were a unix timestamp, you'd need to set ``input`` to ``timestamp``:: - $builder->add('startTime', 'time', array( + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('startTime', TimeType::class, array( 'input' => 'timestamp', 'widget' => 'choice', )); From 832a12a316029ce02d2910625c100e7a8fc90fde Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 27 Nov 2015 17:34:32 -0500 Subject: [PATCH 2/4] fixing build error --- cookbook/form/form_collections.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/form/form_collections.rst b/cookbook/form/form_collections.rst index 903ef4d3a37..8779406f239 100644 --- a/cookbook/form/form_collections.rst +++ b/cookbook/form/form_collections.rst @@ -135,7 +135,7 @@ Notice that you embed a collection of ``TagType`` forms using the } } -In your controller, you'll create a new form from the ``TaskType``: +In your controller, you'll create a new form from the ``TaskType``:: // src/AppBundle/Controller/TaskController.php namespace AppBundle\Controller; From feb68dd29181fef80f4c65beafa5c75ad2245812 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 29 Nov 2015 22:47:27 -0500 Subject: [PATCH 3/4] Completely updating the form type reference section for the text -> TextType changes --- reference/forms/types.rst | 9 +++- reference/forms/types/birthday.rst | 22 +++++----- reference/forms/types/button.rst | 10 ++--- reference/forms/types/checkbox.rst | 11 +++-- reference/forms/types/choice.rst | 12 +++--- reference/forms/types/collection.rst | 27 ++++++------ reference/forms/types/country.rst | 25 +++++------ reference/forms/types/currency.rst | 28 ++++++------ reference/forms/types/date.rst | 17 +++++--- reference/forms/types/datetime.rst | 20 ++++----- reference/forms/types/email.rst | 13 +++--- reference/forms/types/entity.rst | 43 ++++++++++--------- reference/forms/types/file.rst | 13 +++--- reference/forms/types/form.rst | 12 +++--- reference/forms/types/hidden.rst | 9 ++-- reference/forms/types/integer.rst | 11 +++-- reference/forms/types/language.rst | 27 ++++++------ reference/forms/types/locale.rst | 27 ++++++------ reference/forms/types/map.rst.inc | 64 ++++++++++++++-------------- reference/forms/types/money.rst | 13 +++--- reference/forms/types/number.rst | 11 +++-- reference/forms/types/password.rst | 15 +++---- reference/forms/types/percent.rst | 13 +++--- reference/forms/types/radio.rst | 24 +++++------ reference/forms/types/range.rst | 13 +++--- reference/forms/types/repeated.rst | 22 +++++----- reference/forms/types/reset.rst | 10 ++--- reference/forms/types/search.rst | 11 +++-- reference/forms/types/submit.rst | 10 ++--- reference/forms/types/text.rst | 13 +++--- reference/forms/types/textarea.rst | 11 +++-- reference/forms/types/time.rst | 15 +++---- reference/forms/types/timezone.rst | 29 ++++++------- reference/forms/types/url.rst | 13 +++--- 34 files changed, 299 insertions(+), 324 deletions(-) diff --git a/reference/forms/types.rst b/reference/forms/types.rst index 5df657d1910..6dbfb54010c 100644 --- a/reference/forms/types.rst +++ b/reference/forms/types.rst @@ -4,6 +4,13 @@ Form Types Reference ==================== +.. versionadded:: 2.8 + To denote the form type, you have to use the fully qualified class name - like + ``TextType::class`` in PHP 5.5+ or ``Symfony\Component\Form\Extension\Core\Type\TextType``. + Before Symfony 2.8, you could use an alias for each type like ``text`` or + ``date``. The old alias syntax will still work until Symfony 3.0. For more details, + see the `2.8 UPGRADE Log`_. + .. toctree:: :maxdepth: 1 :hidden: @@ -49,7 +56,7 @@ Form Types Reference types/form A form is composed of *fields*, each of which are built with the help of -a field *type* (e.g. a ``text`` type, ``choice`` type, etc). Symfony comes +a field *type* (e.g. ``TextType``, ``ChoiceType``, etc). Symfony comes standard with a large list of field types that can be used in your application. Supported Field Types diff --git a/reference/forms/types/birthday.rst b/reference/forms/types/birthday.rst index 740c885efba..5a31c5cde4c 100644 --- a/reference/forms/types/birthday.rst +++ b/reference/forms/types/birthday.rst @@ -1,16 +1,16 @@ .. index:: - single: Forms; Fields; birthday + single: Forms; Fields; BirthdayType -birthday Field Type -=================== +BirthdayType Field +================== -A :doc:`date ` field that specializes in handling +A :doc:`DateType ` field that specializes in handling birthdate data. Can be rendered as a single text box, three text boxes (month, day and year), or three select boxes. -This type is essentially the same as the :doc:`date ` +This type is essentially the same as the :doc:`DateType ` type, but with a more appropriate default for the `years`_ option. The `years`_ option defaults to 120 years ago to the current year. @@ -22,7 +22,7 @@ option defaults to 120 years ago to the current year. +----------------------+-------------------------------------------------------------------------------+ | Overridden options | - `years`_ | +----------------------+-------------------------------------------------------------------------------+ -| Inherited options | from the :doc:`date ` type: | +| Inherited options | from the :doc:`DateType `: | | | | | | - `days`_ | | | - `placeholder`_ | @@ -33,7 +33,7 @@ option defaults to 120 years ago to the current year. | | - `view_timezone`_ | | | - `widget`_ | | | | -| | from the :doc:`form ` type: | +| | from the :doc:`FormType `: | | | | | | - `data`_ | | | - `disabled`_ | @@ -43,7 +43,7 @@ option defaults to 120 years ago to the current year. | | - `mapped`_ | | | - `read_only`_ (deprecated as of 2.8) | +----------------------+-------------------------------------------------------------------------------+ -| Parent type | :doc:`date ` | +| Parent type | :doc:`DateType ` | +----------------------+-------------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\BirthdayType` | +----------------------+-------------------------------------------------------------------------------+ @@ -62,8 +62,7 @@ relevant when the ``widget`` option is set to ``choice``. Inherited Options ----------------- -These options inherit from the :doc:`date ` -type: +These options inherit from the :doc:`DateType `: .. include:: /reference/forms/types/options/days.rst.inc @@ -81,8 +80,7 @@ type: .. include:: /reference/forms/types/options/date_widget.rst.inc -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/button.rst b/reference/forms/types/button.rst index 2ed5ac1750d..17910f6a67c 100644 --- a/reference/forms/types/button.rst +++ b/reference/forms/types/button.rst @@ -1,11 +1,11 @@ .. index:: - single: Forms; Fields; button + single: Forms; Fields; ButtonType -button Field Type -================= +ButtonType Field +================ .. versionadded:: 2.3 - The ``button`` type was introduced in Symfony 2.3 + The ``ButtonType`` was introduced in Symfony 2.3 A simple, non-responsive button. @@ -28,7 +28,7 @@ Inherited Options The following options are defined in the :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\BaseType` class. The ``BaseType`` class is the parent class for both the ``button`` type -and the :doc:`form type `, but it is not part +and the :doc:`FormType `, but it is not part of the form type tree (i.e. it can not be used as a form type on its own). .. include:: /reference/forms/types/options/button_attr.rst.inc diff --git a/reference/forms/types/checkbox.rst b/reference/forms/types/checkbox.rst index 5f774a3498e..1f1a0efa25d 100644 --- a/reference/forms/types/checkbox.rst +++ b/reference/forms/types/checkbox.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; checkbox + single: Forms; Fields; CheckboxType -checkbox Field Type -=================== +CheckboxType Field +================== Creates a single input checkbox. This should always be used for a field that has a boolean value: if the box is checked, the field will be set to @@ -26,7 +26,7 @@ true, if the box is unchecked, the value will be set to false. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+------------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\CheckboxType` | +-------------+------------------------------------------------------------------------+ @@ -59,8 +59,7 @@ Overridden Options Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index 1a9c101fbcf..be0bf17265a 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; choice + single: Forms; Fields; ChoiceType -choice Field Type (select drop-downs, radio buttons & checkboxes) -================================================================= +ChoiceType Field (select drop-downs, radio buttons & checkboxes) +================================================================ A multi-purpose field used to allow the user to "choose" one or more options. It can be rendered as a ``select`` tag, radio buttons, or checkboxes. @@ -41,7 +41,7 @@ To use this field, you must specify *either* ``choices`` or ``choice_loader`` op | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+------------------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+------------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType` | +-------------+------------------------------------------------------------------------------+ @@ -91,6 +91,7 @@ this example, the underlying data is some ``Category`` object that has a ``getNa method:: use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + use AppBundle\Entity\Category; // ... $builder->add('category', ChoiceType::class, [ @@ -333,8 +334,7 @@ the parent field (the form in most cases). Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/by_reference.rst.inc diff --git a/reference/forms/types/collection.rst b/reference/forms/types/collection.rst index 3dfdddfe435..269f00977d2 100644 --- a/reference/forms/types/collection.rst +++ b/reference/forms/types/collection.rst @@ -1,12 +1,12 @@ .. index:: - single: Forms; Fields; collection + single: Forms; Fields; CollectionType -collection Field Type -===================== +CollectionType Field +==================== This field type is used to render a "collection" of some field or form. -In the easiest sense, it could be an array of ``text`` fields that populate -an array ``emails`` field. In more complex examples, you can embed entire +In the easiest sense, it could be an array of ``TextType`` fields that populate +an array ``emails`` values. In more complex examples, you can embed entire forms, which is useful when creating forms that expose one-to-many relationships (e.g. a product from where you can manage many related product photos). @@ -32,7 +32,7 @@ photos). | | - `mapped`_ | | | - `required`_ | +-------------+-----------------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+-----------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType` | +-------------+-----------------------------------------------------------------------------+ @@ -287,8 +287,8 @@ entry_options **type**: ``array`` **default**: ``array()`` 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 ` -type as your `entry_type`_ option (e.g. for a collection of drop-down menus), +option. For example, if you used the :doc:`ChoiceType ` +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:: @@ -317,9 +317,9 @@ entry_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 ` type. If you want +This is the field type for each item in this collection (e.g. ``TextType``, +``ChoiceType``, etc). For example, if you have an array of email addresses, +you'd use the :doc:`EmailType `. 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. @@ -374,9 +374,8 @@ not replaced with the same value. Inherited Options ----------------- -These options inherit from the :doc:`form ` -type. Not all options are listed here - only the most applicable to this -type: +These options inherit from the :doc:`FormType `. +Not all options are listed here - only the most applicable to this type: .. _reference-form-types-by-reference: diff --git a/reference/forms/types/country.rst b/reference/forms/types/country.rst index e7b7226c067..abe34f03546 100644 --- a/reference/forms/types/country.rst +++ b/reference/forms/types/country.rst @@ -1,10 +1,10 @@ .. index:: single: Forms; Fields; country -country Field Type -================== +CountryType Field +================= -The ``country`` type is a subset of the ``ChoiceType`` that displays countries +The ``CountryType`` is a subset of the ``ChoiceType`` that displays countries of the world. As an added bonus, the country names are displayed in the language of the user. @@ -14,10 +14,9 @@ The "value" for each country is the two-letter country code. The locale of your user is guessed using :phpmethod:`Locale::getDefault` -Unlike the ``choice`` type, you don't need to specify a ``choices`` or -``choice_list`` option as the field type automatically uses all of the countries -of the world. You *can* specify either of these options manually, but then -you should just use the ``choice`` type directly. +Unlike the ``ChoiceType``, you don't need to specify a ``choices`` option as the +field type automatically uses all of the countries of the world. You *can* specify +the option manually, but then you should just use the ``ChoiceType`` directly. +-------------+-----------------------------------------------------------------------+ | Rendered as | can be various tags (see :ref:`forms-reference-choice-tags`) | @@ -25,7 +24,7 @@ you should just use the ``choice`` type directly. | Overridden | - `choices`_ | | options | | +-------------+-----------------------------------------------------------------------+ -| Inherited | from the :doc:`choice ` type | +| Inherited | from the :doc:`ChoiceType ` | | options | | | | - `placeholder`_ | | | - `error_bubbling`_ | @@ -34,7 +33,7 @@ you should just use the ``choice`` type directly. | | - `multiple`_ | | | - `preferred_choices`_ | | | | -| | from the :doc:`form ` type | +| | from the :doc:`FormType ` | | | | | | - `data`_ | | | - `disabled`_ | @@ -45,7 +44,7 @@ you should just use the ``choice`` type directly. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+-----------------------------------------------------------------------+ -| Parent type | :doc:`choice ` | +| Parent type | :doc:`ChoiceType ` | +-------------+-----------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\CountryType` | +-------------+-----------------------------------------------------------------------+ @@ -64,8 +63,7 @@ The locale is used to translate the countries names. Inherited Options ----------------- -These options inherit from the :doc:`choice ` -type: +These options inherit from the :doc:`ChoiceType `: .. include:: /reference/forms/types/options/placeholder.rst.inc @@ -79,8 +77,7 @@ type: .. include:: /reference/forms/types/options/preferred_choices.rst.inc -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/currency.rst b/reference/forms/types/currency.rst index 5fa7d19b720..3281314e4cf 100644 --- a/reference/forms/types/currency.rst +++ b/reference/forms/types/currency.rst @@ -1,17 +1,15 @@ .. index:: single: Forms; Fields; currency -currency Field Type -=================== +CurrencyType Field +================== -The ``currency`` type is a subset of the -:doc:`choice type ` that allows the user -to select from a large list of `3-letter ISO 4217`_ currencies. +The ``CurrencyType`` is a subset of the :doc:`ChoiceType ` +that allows the user to select from a large list of `3-letter ISO 4217`_ currencies. -Unlike the ``choice`` type, you don't need to specify a ``choices`` or -``choice_list`` option as the field type automatically uses a large list -of currencies. You *can* specify either of these options manually, but then -you should just use the ``choice`` type directly. +Unlike the ``ChoiceType``, you don't need to specify a ``choices`` option as the +field type automatically uses a large list of currencies. You *can* specify the option +manually, but then you should just use the ``ChoiceType`` directly. +-------------+------------------------------------------------------------------------+ | Rendered as | can be various tags (see :ref:`forms-reference-choice-tags`) | @@ -19,7 +17,7 @@ you should just use the ``choice`` type directly. | Overridden | - `choices`_ | | options | | +-------------+------------------------------------------------------------------------+ -| Inherited | from the :doc:`choice ` type | +| Inherited | from the :doc:`ChoiceType ` | | options | | | | - `placeholder`_ | | | - `error_bubbling`_ | @@ -27,7 +25,7 @@ you should just use the ``choice`` type directly. | | - `multiple`_ | | | - `preferred_choices`_ | | | | -| | from the :doc:`form ` type | +| | from the :doc:`FormType ` type | | | | | | - `data`_ | | | - `disabled`_ | @@ -38,7 +36,7 @@ you should just use the ``choice`` type directly. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+------------------------------------------------------------------------+ -| Parent type | :doc:`choice ` | +| Parent type | :doc:`ChoiceType ` | +-------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\CurrencyType` | +-------------+------------------------------------------------------------------------+ @@ -56,8 +54,7 @@ The choices option defaults to all currencies. Inherited Options ----------------- -These options inherit from the :doc:`choice` -type: +These options inherit from the :doc:`ChoiceType `: .. include:: /reference/forms/types/options/placeholder.rst.inc @@ -69,8 +66,7 @@ type: .. include:: /reference/forms/types/options/preferred_choices.rst.inc -These options inherit from the :doc:`form` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/date.rst b/reference/forms/types/date.rst index e374b93f946..2d93e10a00f 100644 --- a/reference/forms/types/date.rst +++ b/reference/forms/types/date.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; date + single: Forms; Fields; DateType -date Field Type -=============== +DateType Field +============== A field that allows the user to modify date information via a variety of different HTML elements. @@ -44,7 +44,7 @@ day and year) or three select boxes (see the `widget`_ option). | | - `mapped`_ | | | - `read_only`_ (deprecated as of 2.8) | +----------------------+-----------------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +----------------------+-----------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\DateType` | +----------------------+-----------------------------------------------------------------------------+ @@ -59,6 +59,9 @@ Suppose that you have a ``publishedAt`` field whose underlying date is a ``DateTime`` object. The following configures the ``DateType`` type for that field as three different choice fields:: + use Symfony\Component\Form\Extension\Core\Type\DateType; + // ... + $builder->add('publishedAt', DateType::class, array( 'input' => 'datetime', 'widget' => 'choice', @@ -68,6 +71,9 @@ The ``input`` option *must* be changed to match the type of the underlying date data. For example, if the ``publishedAt`` field's data were a unix timestamp, you'd need to set ``input`` to ``timestamp``:: + use Symfony\Component\Form\Extension\Core\Type\DateType; + // ... + $builder->add('publishedAt', DateType::class, array( 'input' => 'timestamp', 'widget' => 'choice', @@ -146,8 +152,7 @@ error_bubbling Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/datetime.rst b/reference/forms/types/datetime.rst index 58471e175b8..087e99478e9 100644 --- a/reference/forms/types/datetime.rst +++ b/reference/forms/types/datetime.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; datetime + single: Forms; Fields; DateTimeType -datetime Field Type -=================== +DateTimeType Field +================== This field type allows the user to modify data that represents a specific date and time (e.g. ``1984-06-05 12:15:30``). @@ -47,7 +47,7 @@ the data can be a ``DateTime`` object, a string, a timestamp or an array. | | - `mapped`_ | | | - `read_only`_ (deprecated as of 2.8) | +----------------------+-----------------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +----------------------+-----------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\DateTimeType` | +----------------------+-----------------------------------------------------------------------------+ @@ -61,7 +61,7 @@ date_format **type**: ``integer`` or ``string`` **default**: ``IntlDateFormatter::MEDIUM`` Defines the ``format`` option that will be passed down to the date field. -See the :ref:`date type's format option ` +See the :ref:`DateType's format option ` for more details. date_widget @@ -119,8 +119,7 @@ time_widget **type**: ``string`` **default**: ``choice`` -Defines the ``widget`` option for the :doc:`time ` -type +Defines the ``widget`` option for the :doc:`TimeType `. .. include:: /reference/forms/types/options/view_timezone.rst.inc @@ -129,8 +128,8 @@ widget **type**: ``string`` **default**: ``null`` -Defines the ``widget`` option for both the :doc:`date ` -type and :doc:`time ` type. This can be overridden +Defines the ``widget`` option for both the :doc:`DateType ` +and :doc:`TimeType `. This can be overridden with the `date_widget`_ and `time_widget`_ options. .. include:: /reference/forms/types/options/with_minutes.rst.inc @@ -161,8 +160,7 @@ error_bubbling Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/email.rst b/reference/forms/types/email.rst index 58b68da5cc8..9e70150ec5a 100644 --- a/reference/forms/types/email.rst +++ b/reference/forms/types/email.rst @@ -1,10 +1,10 @@ .. index:: - single: Forms; Fields; email + single: Forms; Fields; EmailType -email Field Type -================ +EmailType Field +=============== -The ``email`` field is a text field that is rendered using the HTML5 +The ``EmailType`` field is a text field that is rendered using the HTML5 ```` tag. +-------------+---------------------------------------------------------------------+ @@ -23,7 +23,7 @@ The ``email`` field is a text field that is rendered using the HTML5 | | - `required`_ | | | - `trim`_ | +-------------+---------------------------------------------------------------------+ -| Parent type | :doc:`text ` | +| Parent type | :doc:`TextType ` | +-------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\EmailType` | +-------------+---------------------------------------------------------------------+ @@ -31,8 +31,7 @@ The ``email`` field is a text field that is rendered using the HTML5 Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/entity.rst b/reference/forms/types/entity.rst index a0487477029..4eacb7078f8 100644 --- a/reference/forms/types/entity.rst +++ b/reference/forms/types/entity.rst @@ -1,10 +1,10 @@ .. index:: - single: Forms; Fields; choice + single: Forms; Fields; EntityType -entity Field Type -================= +EntityType Field +================ -A special ``choice`` field that's designed to load options from a Doctrine +A special ``ChoiceType`` field that's designed to load options from a Doctrine entity. For example, if you have a ``Category`` entity, you could use this field to display a ``select`` field of all, or some, of the ``Category`` objects from the database. @@ -20,7 +20,7 @@ objects from the database. | Overridden | - `choices`_ | | options | | +-------------+------------------------------------------------------------------+ -| Inherited | from the :doc:`choice ` type: | +| Inherited | from the :doc:`ChoiceType `: | | options | | | | - `placeholder`_ | | | - `expanded`_ | @@ -28,7 +28,7 @@ objects from the database. | | - `preferred_choices`_ | | | - `group_by`_ | | | | -| | from the :doc:`form ` type: | +| | from the :doc:`FormType `: | | | | | | - `data`_ | | | - `disabled`_ | @@ -41,7 +41,7 @@ objects from the database. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+------------------------------------------------------------------+ -| Parent type | :doc:`choice ` | +| Parent type | :doc:`ChoiceType ` | +-------------+------------------------------------------------------------------+ | Class | :class:`Symfony\\Bridge\\Doctrine\\Form\\Type\\EntityType` | +-------------+------------------------------------------------------------------+ @@ -56,15 +56,18 @@ be listed inside the choice field:: // ... $builder->add('users', EntityType::class, array( - 'class' => 'AcmeHelloBundle:User', + 'class' => 'AppBundle:User', 'choice_label' => 'username', )); In this case, all ``User`` objects will be loaded from the database and rendered as either a ``select`` tag, a set or radio buttons or a series of checkboxes (this depends on the ``multiple`` and ``expanded`` values). -If the entity object does not have a ``__toString()`` method the ``choice_label`` -option is needed. +Because of the `choice_label`_ option, the ``username`` property (usually by calling +``getUsername()``) will be used as the text to display in the field. + +If you omit the ``choice_label`` option, then your entity *must* have a ``__toString()`` +method. Using a Custom Query for the Entities ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -78,7 +81,7 @@ the ``query_builder`` option. The easiest way to use the option is as follows:: // ... $builder->add('users', EntityType::class, array( - 'class' => 'AcmeHelloBundle:User', + 'class' => 'AppBundle:User', 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('u') ->orderBy('u.username', 'ASC'); @@ -100,7 +103,7 @@ then you can supply the ``choices`` option directly:: // ... $builder->add('users', EntityType::class, array( - 'class' => 'AcmeHelloBundle:User', + 'class' => 'AppBundle:User', 'choices' => $group->getUsers(), )); @@ -114,8 +117,8 @@ class **type**: ``string`` **required** -The class of your entity (e.g. ``AcmeStoreBundle:Category``). This can be -a fully-qualified class name (e.g. ``Acme\StoreBundle\Entity\Category``) +The class of your entity (e.g. ``AppBundle:Category``). This can be +a fully-qualified class name (e.g. ``AppBundle\Entity\Category``) or the short alias name (as shown prior). choice_label @@ -167,7 +170,7 @@ more detais, see the main :ref:`choice_label ` docu // ... $builder->add('gender', EntityType::class, array( - 'class' => 'MyBundle:Gender', + 'class' => 'AppBundle:Category', 'choice_label' => 'translations[en].name', )); @@ -206,8 +209,7 @@ See :ref:`reference-forms-entity-choices`. Inherited Options ----------------- -These options inherit from the :doc:`choice ` -type: +These options inherit from the :doc:`ChoiceType `: .. include:: /reference/forms/types/options/placeholder.rst.inc @@ -229,11 +231,10 @@ type: .. note:: - This option expects an array of entity objects, unlike the ``choice`` - field that requires an array of keys. + This option expects an array of entity objects (that's actually the same as with + the ``ChoiceType`` field, whichs requires an array of the preferred "values"). -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/file.rst b/reference/forms/types/file.rst index b31b72a3f18..2f964867111 100644 --- a/reference/forms/types/file.rst +++ b/reference/forms/types/file.rst @@ -1,10 +1,10 @@ .. index:: - single: Forms; Fields; file + single: Forms; Fields; FileType -file Field Type -=============== +FileType Field +============== -The ``file`` type represents a file input in your form. +The ``FileType`` represents a file input in your form. +-------------+---------------------------------------------------------------------+ | Rendered as | ``input`` ``file`` field | @@ -24,7 +24,7 @@ The ``file`` type represents a file input in your form. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+---------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\FileType` | +-------------+---------------------------------------------------------------------+ @@ -115,8 +115,7 @@ value is empty. Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/disabled.rst.inc diff --git a/reference/forms/types/form.rst b/reference/forms/types/form.rst index 860ff593d45..ccd229795d4 100644 --- a/reference/forms/types/form.rst +++ b/reference/forms/types/form.rst @@ -1,11 +1,11 @@ .. index:: - single: Forms; Fields; form + single: Forms; Fields; FormType -form Field Type -=============== +FormType Field +============== -The ``form`` type predefines a couple of options that are then available -on all types for which ``form`` is the parent type. +The ``FormType`` predefines a couple of options that are then available +on all types for which ``FormType`` is the parent. +-----------+--------------------------------------------------------------------+ | Options | - `action`_ | @@ -146,7 +146,7 @@ Inherited Options The following options are defined in the :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\BaseType` class. The ``BaseType`` class is the parent class for both the ``form`` type and -the :doc:`button type `, but it is not part +the :doc:`ButtonType `, but it is not part of the form type tree (i.e. it can not be used as a form type on its own). .. include:: /reference/forms/types/options/attr.rst.inc diff --git a/reference/forms/types/hidden.rst b/reference/forms/types/hidden.rst index 272eb853852..e211c526f63 100644 --- a/reference/forms/types/hidden.rst +++ b/reference/forms/types/hidden.rst @@ -1,8 +1,8 @@ .. index:: single: Forms; Fields; hidden -hidden Field Type -================= +HiddenType Field +================ The hidden type represents a hidden input field. @@ -18,7 +18,7 @@ The hidden type represents a hidden input field. | | - `mapped`_ | | | - `property_path`_ | +-------------+----------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+----------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\HiddenType` | +-------------+----------------------------------------------------------------------+ @@ -45,8 +45,7 @@ Hidden fields cannot have a required attribute. Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/integer.rst b/reference/forms/types/integer.rst index b2d4348861e..19fff1d4e89 100644 --- a/reference/forms/types/integer.rst +++ b/reference/forms/types/integer.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; integer + single: Forms; Fields; IntegerType -integer Field Type -================== +IntegerType Field +================= Renders an input "number" field. Basically, this is a text field that's good at handling data that's in an integer form. The input ``number`` field @@ -36,7 +36,7 @@ integers. By default, all non-integer values (e.g. 6.78) will round down | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+-----------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+-----------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\IntegerType` | +-------------+-----------------------------------------------------------------------+ @@ -85,8 +85,7 @@ Overridden Options Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/language.rst b/reference/forms/types/language.rst index 621dc08b3cd..aa2ea09b44f 100644 --- a/reference/forms/types/language.rst +++ b/reference/forms/types/language.rst @@ -1,10 +1,10 @@ .. index:: - single: Forms; Fields; language + single: Forms; Fields; LanguageType -language Field Type -=================== +LanguageType Field +================== -The ``language`` type is a subset of the ``ChoiceType`` that allows the +The ``LanguageType`` is a subset of the ``ChoiceType`` that allows the user to select from a large list of languages. As an added bonus, the language names are displayed in the language of the user. @@ -15,10 +15,9 @@ in the `International Components for Unicode`_ (e.g. ``fr`` or ``zh_Hant``). The locale of your user is guessed using :phpmethod:`Locale::getDefault` -Unlike the ``choice`` type, you don't need to specify a ``choices`` or -``choice_list`` option as the field type automatically uses a large list -of languages. You *can* specify either of these options manually, but then -you should just use the ``choice`` type directly. +Unlike the ``ChoiceType``, you don't need to specify a ``choices`` option as the +field type automatically uses a large list of languages. You *can* specify the option +manually, but then you should just use the ``ChoiceType`` directly. +-------------+------------------------------------------------------------------------+ | Rendered as | can be various tags (see :ref:`forms-reference-choice-tags`) | @@ -26,7 +25,7 @@ you should just use the ``choice`` type directly. | Overridden | - `choices`_ | | options | | +-------------+------------------------------------------------------------------------+ -| Inherited | from the :doc:`choice ` type | +| Inherited | from the :doc:`ChoiceType ` | | options | | | | - `placeholder`_ | | | - `error_bubbling`_ | @@ -35,7 +34,7 @@ you should just use the ``choice`` type directly. | | - `multiple`_ | | | - `preferred_choices`_ | | | | -| | from the :doc:`form ` type | +| | from the :doc:`FormType ` | | | | | | - `data`_ | | | - `disabled`_ | @@ -46,7 +45,7 @@ you should just use the ``choice`` type directly. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+------------------------------------------------------------------------+ -| Parent type | :doc:`choice ` | +| Parent type | :doc:`ChoiceType ` | +-------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\LanguageType` | +-------------+------------------------------------------------------------------------+ @@ -65,8 +64,7 @@ The default locale is used to translate the languages names. Inherited Options ----------------- -These options inherit from the :doc:`choice ` -type: +These options inherit from the :doc:`ChoiceType `: .. include:: /reference/forms/types/options/placeholder.rst.inc @@ -80,8 +78,7 @@ type: .. include:: /reference/forms/types/options/preferred_choices.rst.inc -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/locale.rst b/reference/forms/types/locale.rst index c1ddaf47ed0..83ae8acfa81 100644 --- a/reference/forms/types/locale.rst +++ b/reference/forms/types/locale.rst @@ -1,10 +1,10 @@ .. index:: - single: Forms; Fields; locale + single: Forms; Fields; LocaleType -locale Field Type -================= +LocaleType Field +================ -The ``locale`` type is a subset of the ``ChoiceType`` that allows the user +The ``LocaleType`` is a subset of the ``ChoiceType`` that allows the user to select from a large list of locales (language+country). As an added bonus, the locale names are displayed in the language of the user. @@ -17,10 +17,9 @@ for French/France). The locale of your user is guessed using :phpmethod:`Locale::getDefault` -Unlike the ``choice`` type, you don't need to specify a ``choices`` or -``choice_list`` option as the field type automatically uses a large list -of locales. You *can* specify either of these options manually, but then -you should just use the ``choice`` type directly. +Unlike the ``ChoiceType``, you don't need to specify a ``choices`` option as the +field type automatically uses a large list of locales. You *can* specify these options +manually, but then you should just use the ``ChoiceType`` directly. +-------------+------------------------------------------------------------------------+ | Rendered as | can be various tags (see :ref:`forms-reference-choice-tags`) | @@ -28,7 +27,7 @@ you should just use the ``choice`` type directly. | Overridden | - `choices`_ | | options | | +-------------+------------------------------------------------------------------------+ -| Inherited | from the :doc:`choice ` type | +| Inherited | from the :doc:`ChoiceType ` | | options | | | | - `placeholder`_ | | | - `error_bubbling`_ | @@ -37,7 +36,7 @@ you should just use the ``choice`` type directly. | | - `multiple`_ | | | - `preferred_choices`_ | | | | -| | from the :doc:`form ` type | +| | from the :doc:`FormType ` | | | | | | - `data`_ | | | - `disabled`_ | @@ -48,7 +47,7 @@ you should just use the ``choice`` type directly. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+------------------------------------------------------------------------+ -| Parent type | :doc:`choice ` | +| Parent type | :doc:`ChoiceType ` | +-------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\LocaleType` | +-------------+------------------------------------------------------------------------+ @@ -67,8 +66,7 @@ specify the language. Inherited Options ----------------- -These options inherit from the :doc:`choice ` -type: +These options inherit from the :doc:`ChoiceType `: .. include:: /reference/forms/types/options/placeholder.rst.inc @@ -82,8 +80,7 @@ type: .. include:: /reference/forms/types/options/preferred_choices.rst.inc -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/map.rst.inc b/reference/forms/types/map.rst.inc index de0e07db282..4351908de8a 100644 --- a/reference/forms/types/map.rst.inc +++ b/reference/forms/types/map.rst.inc @@ -1,63 +1,63 @@ Text Fields ~~~~~~~~~~~ -* :doc:`text ` -* :doc:`textarea ` -* :doc:`email ` -* :doc:`integer ` -* :doc:`money ` -* :doc:`number ` -* :doc:`password ` -* :doc:`percent ` -* :doc:`search ` -* :doc:`url ` -* :doc:`range ` +* :doc:`TextType ` +* :doc:`TextareaType ` +* :doc:`EmailType ` +* :doc:`IntegerType ` +* :doc:`MoneyType ` +* :doc:`NumberType ` +* :doc:`PasswordType ` +* :doc:`PercentType ` +* :doc:`SearchType ` +* :doc:`UrlType ` +* :doc:`RangeType ` Choice Fields ~~~~~~~~~~~~~ -* :doc:`choice ` -* :doc:`entity ` -* :doc:`country ` -* :doc:`language ` -* :doc:`locale ` -* :doc:`timezone ` -* :doc:`currency ` +* :doc:`ChoiceType ` +* :doc:`EntityType ` +* :doc:`CountryType ` +* :doc:`LanguageType ` +* :doc:`LocaleType ` +* :doc:`TimezoneType ` +* :doc:`CurrencyType ` Date and Time Fields ~~~~~~~~~~~~~~~~~~~~ -* :doc:`date ` -* :doc:`datetime ` -* :doc:`time ` -* :doc:`birthday ` +* :doc:`DateType ` +* :doc:`DateTimeType ` +* :doc:`TimeType ` +* :doc:`BirthdayType ` Other Fields ~~~~~~~~~~~~ -* :doc:`checkbox ` -* :doc:`file ` -* :doc:`radio ` +* :doc:`CheckboxType ` +* :doc:`FileType ` +* :doc:`RadioType ` Field Groups ~~~~~~~~~~~~ -* :doc:`collection ` -* :doc:`repeated ` +* :doc:`CollectionType ` +* :doc:`RepeatedType ` Hidden Fields ~~~~~~~~~~~~~ -* :doc:`hidden ` +* :doc:`HiddenType ` Buttons ~~~~~~~ -* :doc:`button` -* :doc:`reset` -* :doc:`submit` +* :doc:`ButtonType ` +* :doc:`ResetType ` +* :doc:`SubmitType ` Base Fields ~~~~~~~~~~~ -* :doc:`form ` +* :doc:`FormType ` diff --git a/reference/forms/types/money.rst b/reference/forms/types/money.rst index a9683f02abc..f97dec52d51 100644 --- a/reference/forms/types/money.rst +++ b/reference/forms/types/money.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; money + single: Forms; Fields; MoneyType -money Field Type -================ +MoneyType Field +=============== Renders an input text field and specializes in handling submitted "money" data. @@ -35,7 +35,7 @@ how the input and output of the data is handled. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+---------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\MoneyType` | +-------------+---------------------------------------------------------------------+ @@ -65,7 +65,7 @@ If, for some reason, you need to divide your starting value by a number before rendering it to the user, you can use the ``divisor`` option. For example:: - use Symfony\Component\Form\Extension\Core\Type\FileType; + use Symfony\Component\Form\Extension\Core\Type\MoneyType; // ... $builder->add('price', MoneyType::class, array( @@ -101,8 +101,7 @@ Overridden Options Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/number.rst b/reference/forms/types/number.rst index 59094ac1bb9..3d67a154957 100644 --- a/reference/forms/types/number.rst +++ b/reference/forms/types/number.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; number + single: Forms; Fields; NumberType -number Field Type -================= +NumberType Field +================ Renders an input text field and specializes in handling number input. This type offers different options for the scale, rounding and grouping @@ -31,7 +31,7 @@ that you want to use for your number. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+----------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+----------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\NumberType` | +-------------+----------------------------------------------------------------------+ @@ -80,8 +80,7 @@ Overridden Options Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/password.rst b/reference/forms/types/password.rst index 3e971ff113f..f5db4f721be 100644 --- a/reference/forms/types/password.rst +++ b/reference/forms/types/password.rst @@ -1,10 +1,10 @@ .. index:: - single: Forms; Fields; password + single: Forms; Fields; PasswordType -password Field Type -=================== +PasswordType Field +================== -The ``password`` field renders an input password text box. +The ``PasswordType`` field renders an input password text box. +-------------+------------------------------------------------------------------------+ | Rendered as | ``input`` ``password`` field | @@ -25,7 +25,7 @@ The ``password`` field renders an input password text box. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+------------------------------------------------------------------------+ -| Parent type | :doc:`text ` | +| Parent type | :doc:`TextType ` | +-------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\PasswordType` | +-------------+------------------------------------------------------------------------+ @@ -54,7 +54,7 @@ trim **type**: ``boolean`` **default**: ``false`` -Unlike the rest of form types, the ``password`` type doesn't apply the +Unlike the rest of form types, the ``PasswordType`` doesn't apply the :phpfunction:`trim` function to the value submitted by the user. This ensures that the password is merged back onto the underlying object exactly as it was typed by the user. @@ -62,8 +62,7 @@ by the user. Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/disabled.rst.inc diff --git a/reference/forms/types/percent.rst b/reference/forms/types/percent.rst index 0efc8c7c2c2..14ad60281bf 100644 --- a/reference/forms/types/percent.rst +++ b/reference/forms/types/percent.rst @@ -1,11 +1,11 @@ .. index:: - single: Forms; Fields; percent + single: Forms; Fields; PercentType -percent Field Type -================== +PercentType Field +================= -The ``percent`` type renders an input text field and specializes in handling +The ``PercentType`` renders an input text field and specializes in handling percentage data. If your percentage data is stored as a decimal (e.g. ``.95``), you can use this field out-of-the-box. If you store your data as a number (e.g. ``95``), you should set the ``type`` option to ``integer``. @@ -34,7 +34,7 @@ This field adds a percentage sign "``%``" after the input box. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+-----------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+-----------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\PercentType` | +-------------+-----------------------------------------------------------------------+ @@ -82,8 +82,7 @@ Overridden Options Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/radio.rst b/reference/forms/types/radio.rst index b1adec4c6ea..cd7b0cc9d68 100644 --- a/reference/forms/types/radio.rst +++ b/reference/forms/types/radio.rst @@ -1,26 +1,26 @@ .. index:: - single: Forms; Fields; radio + single: Forms; Fields; RadioType -radio Field Type -================ +RadioType Field +=============== Creates a single radio button. If the radio button is selected, the field will be set to the specified value. Radio buttons cannot be unchecked - the value only changes when another radio button with the same name gets checked. -The ``radio`` type isn't usually used directly. More commonly it's used -internally by other types such as :doc:`choice `. -If you want to have a boolean field, use :doc:`checkbox `. +The ``RadioType`` isn't usually used directly. More commonly it's used +internally by other types such as :doc:`ChoiceType `. +If you want to have a boolean field, use :doc:`CheckboxType `. +-------------+---------------------------------------------------------------------+ | Rendered as | ``input`` ``radio`` field | +-------------+---------------------------------------------------------------------+ -| Inherited | from the :doc:`checkbox ` type: | +| Inherited | from the :doc:`CheckboxType `: | | options | | | | - `value`_ | | | | -| | from the :doc:`form ` type: | +| | from the :doc:`FormType `: | | | | | | - `data`_ | | | - `disabled`_ | @@ -33,7 +33,7 @@ If you want to have a boolean field, use :doc:`checkbox ` | +| Parent type | :doc:`CheckboxType ` | +-------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\RadioType` | +-------------+---------------------------------------------------------------------+ @@ -41,13 +41,11 @@ If you want to have a boolean field, use :doc:`checkbox ` -type: +These options inherit from the :doc:`CheckboxType `: .. include:: /reference/forms/types/options/value.rst.inc -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/range.rst b/reference/forms/types/range.rst index 0a1e8bb855a..a59082adb78 100644 --- a/reference/forms/types/range.rst +++ b/reference/forms/types/range.rst @@ -1,10 +1,10 @@ .. index:: - single: Forms; Fields; range + single: Forms; Fields; RangeType -range Field Type -================ +RangeType Field +=============== -The ``range`` field is a slider that is rendered using the HTML5 +The ``RangeType`` field is a slider that is rendered using the HTML5 ```` tag. +-------------+---------------------------------------------------------------------+ @@ -22,7 +22,7 @@ The ``range`` field is a slider that is rendered using the HTML5 | | - `required`_ | | | - `trim`_ | +-------------+---------------------------------------------------------------------+ -| Parent type | :doc:`text ` | +| Parent type | :doc:`TextType ` | +-------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\RangeType` | +-------------+---------------------------------------------------------------------+ @@ -45,8 +45,7 @@ Basic Usage Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/attr.rst.inc diff --git a/reference/forms/types/repeated.rst b/reference/forms/types/repeated.rst index b091cb33fb2..8c7bca02a87 100644 --- a/reference/forms/types/repeated.rst +++ b/reference/forms/types/repeated.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; repeated + single: Forms; Fields; RepeatedType -repeated Field Type -=================== +RepeatedType Field +================== This is a special field "group", that creates two identical fields whose values must match (or a validation error is thrown). The most common use @@ -28,7 +28,7 @@ accuracy. | | - `invalid_message_parameters`_ | | | - `mapped`_ | +-------------+------------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\RepeatedType` | +-------------+------------------------------------------------------------------------+ @@ -39,10 +39,11 @@ Example Usage .. code-block:: php use Symfony\Component\Form\Extension\Core\Type\RepeatedType; + use Symfony\Component\Form\Extension\Core\Type\PasswordType; // ... $builder->add('password', RepeatedType::class, array( - 'type' => 'password', + 'type' => PasswordType::class, 'invalid_message' => 'The password fields must match.', 'options' => array('attr' => array('class' => 'password-field')), 'required' => true, @@ -58,7 +59,7 @@ single value (usually a string) that you need. The most important option is ``type``, which can be any field type and determines the actual type of the two underlying fields. The ``options`` option is passed to each of those individual fields, meaning - in this example - any -option supported by the ``password`` type can be passed in this array. +option supported by the ``PasswordType`` can be passed in this array. Rendering ~~~~~~~~~ @@ -120,7 +121,7 @@ first_name This is the actual field name to be used for the first field. This is mostly meaningless, however, as the actual data entered into both of the fields -will be available under the key assigned to the ``repeated`` field itself +will be available under the key assigned to the ``RepeatedType`` field itself (e.g. ``password``). However, if you don't specify a label, this field name is used to "guess" the label for you. @@ -150,7 +151,7 @@ This options array will be passed to each of the two underlying fields. In other words, these are the options that customize the individual field types. For example, if the ``type`` option is set to ``password``, this array might contain the options ``always_empty`` or ``required`` - both -options that are supported by the ``password`` field type. +options that are supported by the ``PasswordType`` field. second_name ~~~~~~~~~~~ @@ -174,7 +175,7 @@ type **type**: ``string`` **default**: ``text`` The two underlying fields will be of this field type. For example, passing -a type of ``password`` will render two password fields. +``PasswordType::class`` will render two password fields. Overridden Options ------------------ @@ -187,8 +188,7 @@ error_bubbling Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/reset.rst b/reference/forms/types/reset.rst index 20b2d9dad70..c3f7c215221 100644 --- a/reference/forms/types/reset.rst +++ b/reference/forms/types/reset.rst @@ -1,11 +1,11 @@ .. index:: - single: Forms; Fields; reset + single: Forms; Fields; ResetType -reset Field Type -================ +ResetType Field +=============== .. versionadded:: 2.3 - The ``reset`` type was introduced in Symfony 2.3 + The ``ResetType`` was introduced in Symfony 2.3 A button that resets all fields to their original values. @@ -18,7 +18,7 @@ A button that resets all fields to their original values. | | - `label_attr`_ | | | - `translation_domain`_ | +----------------------+---------------------------------------------------------------------+ -| Parent type | :doc:`button` | +| Parent type | :doc:`ButtonType ` | +----------------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\ResetType` | +----------------------+---------------------------------------------------------------------+ diff --git a/reference/forms/types/search.rst b/reference/forms/types/search.rst index 69f4f449734..52b23077768 100644 --- a/reference/forms/types/search.rst +++ b/reference/forms/types/search.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; search + single: Forms; Fields; SearchType -search Field Type -================= +SearchType Field +================ This renders an ```` field, which is a text box with special functionality supported by some browsers. @@ -24,7 +24,7 @@ Read about the input search field at `DiveIntoHTML5.info`_ | | - `required`_ | | | - `trim`_ | +-------------+----------------------------------------------------------------------+ -| Parent type | :doc:`text ` | +| Parent type | :doc:`TextType ` | +-------------+----------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\SearchType` | +-------------+----------------------------------------------------------------------+ @@ -32,8 +32,7 @@ Read about the input search field at `DiveIntoHTML5.info`_ Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/disabled.rst.inc diff --git a/reference/forms/types/submit.rst b/reference/forms/types/submit.rst index e8722f8dd0b..aa0d466f06b 100644 --- a/reference/forms/types/submit.rst +++ b/reference/forms/types/submit.rst @@ -1,11 +1,11 @@ .. index:: - single: Forms; Fields; submit + single: Forms; Fields; SubmitType -submit Field Type -================= +SubmitType Field +================ .. versionadded:: 2.3 - The ``submit`` type was introduced in Symfony 2.3 + The ``SubmitType`` type was introduced in Symfony 2.3 A submit button. @@ -19,7 +19,7 @@ A submit button. | | - `translation_domain`_ | | | - `validation_groups`_ | +----------------------+----------------------------------------------------------------------+ -| Parent type | :doc:`button` | +| Parent type | :doc:`ButtonType` | +----------------------+----------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType` | +----------------------+----------------------------------------------------------------------+ diff --git a/reference/forms/types/text.rst b/reference/forms/types/text.rst index 38d1f784a8d..403d5556979 100644 --- a/reference/forms/types/text.rst +++ b/reference/forms/types/text.rst @@ -1,10 +1,10 @@ .. index:: - single: Forms; Fields; text + single: Forms; Fields; TextType -text Field Type -=============== +TextType Field +============== -The text field represents the most basic input text field. +The TextType field represents the most basic input text field. +-------------+--------------------------------------------------------------------+ | Rendered as | ``input`` ``text`` field | @@ -25,7 +25,7 @@ The text field represents the most basic input text field. | Overridden | - `compound`_ | | options | | +-------------+--------------------------------------------------------------------+ -| Parent type | :doc:`form ` | +| Parent type | :doc:`FormType ` | +-------------+--------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType` | +-------------+--------------------------------------------------------------------+ @@ -33,8 +33,7 @@ The text field represents the most basic input text field. Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/textarea.rst b/reference/forms/types/textarea.rst index 18ce38f4a4b..51d14af113e 100644 --- a/reference/forms/types/textarea.rst +++ b/reference/forms/types/textarea.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; textarea + single: Forms; Fields; TextareaType -textarea Field Type -=================== +TextareaType Field +================== Renders a ``textarea`` HTML element. @@ -23,7 +23,7 @@ Renders a ``textarea`` HTML element. | | - `required`_ | | | - `trim`_ | +-------------+------------------------------------------------------------------------+ -| Parent type | :doc:`text ` | +| Parent type | :doc:`TextType ` | +-------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TextareaType` | +-------------+------------------------------------------------------------------------+ @@ -31,8 +31,7 @@ Renders a ``textarea`` HTML element. Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/attr.rst.inc diff --git a/reference/forms/types/time.rst b/reference/forms/types/time.rst index e3a4b405a5e..868555bddae 100644 --- a/reference/forms/types/time.rst +++ b/reference/forms/types/time.rst @@ -1,8 +1,8 @@ .. index:: - single: Forms; Fields; time + single: Forms; Fields; TimeType -time Field Type -=============== +TimeType Field +============== A field to capture time input. @@ -41,7 +41,7 @@ stored as a ``DateTime`` object, a string, a timestamp or an array. | | - `mapped`_ | | | - `read_only`_ (deprecated as of 2.8) | +----------------------+-----------------------------------------------------------------------------+ -| Parent type | form | +| Parent type | FormType | +----------------------+-----------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TimeType` | +----------------------+-----------------------------------------------------------------------------+ @@ -53,7 +53,7 @@ This field type is highly configurable, but easy to use. The most important options are ``input`` and ``widget``. Suppose that you have a ``startTime`` field whose underlying time data is -a ``DateTime`` object. The following configures the ``time`` type for that +a ``DateTime`` object. The following configures the ``TimeType`` for that field as two different choice fields:: use Symfony\Component\Form\Extension\Core\Type\TimeType; @@ -68,7 +68,7 @@ The ``input`` option *must* be changed to match the type of the underlying date data. For example, if the ``startTime`` field's data were a unix timestamp, you'd need to set ``input`` to ``timestamp``:: - use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + use Symfony\Component\Form\Extension\Core\Type\TimeType; // ... $builder->add('startTime', TimeType::class, array( @@ -162,8 +162,7 @@ error_bubbling Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/timezone.rst b/reference/forms/types/timezone.rst index d23ba791b0b..835e7d719c7 100644 --- a/reference/forms/types/timezone.rst +++ b/reference/forms/types/timezone.rst @@ -1,19 +1,18 @@ .. index:: - single: Forms; Fields; timezone + single: Forms; Fields; TimezoneType -timezone Field Type -=================== +TimezoneType Field +================== -The ``timezone`` type is a subset of the ``ChoiceType`` that allows the +The ``TimezoneType`` is a subset of the ``ChoiceType`` that allows the user to select from all possible timezones. The "value" for each timezone is the full timezone name, such as ``America/Chicago`` or ``Europe/Istanbul``. -Unlike the ``choice`` type, you don't need to specify a ``choices`` or -``choice_list`` option as the field type automatically uses a large list -of timezones. You *can* specify either of these options manually, but then -you should just use the ``choice`` type directly. +Unlike the ``ChoiceType``, you don't need to specify a ``choices`` option as the +field type automatically uses a large list of timezones. You *can* specify the option +manually, but then you should just use the ``ChoiceType`` directly. +-------------+------------------------------------------------------------------------+ | Rendered as | can be various tags (see :ref:`forms-reference-choice-tags`) | @@ -21,14 +20,14 @@ you should just use the ``choice`` type directly. | Overridden | - `choices`_ | | options | | +-------------+------------------------------------------------------------------------+ -| Inherited | from the :doc:`choice ` type | +| Inherited | from the :doc:`ChoiceType ` | | options | | | | - `placeholder`_ | | | - `expanded`_ | | | - `multiple`_ | | | - `preferred_choices`_ | | | | -| | from the :doc:`form ` type | +| | from the :doc:`FormType ` | | | | | | - `data`_ | | | - `disabled`_ | @@ -41,7 +40,7 @@ you should just use the ``choice`` type directly. | | - `read_only`_ (deprecated as of 2.8) | | | - `required`_ | +-------------+------------------------------------------------------------------------+ -| Parent type | :doc:`choice ` | +| Parent type | :doc:`ChoiceType ` | +-------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TimezoneType` | +-------------+------------------------------------------------------------------------+ @@ -52,7 +51,7 @@ Overridden Options choices ~~~~~~~ -**default**: :class:`Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\TimezoneChoiceList` +**default**: An array of timezones. The Timezone type defaults the choices to all timezones returned by :phpmethod:`DateTimeZone::listIdentifiers`, broken down by continent. @@ -60,8 +59,7 @@ The Timezone type defaults the choices to all timezones returned by Inherited Options ----------------- -These options inherit from the :doc:`choice ` -type: +These options inherit from the :doc:`ChoiceType `: .. include:: /reference/forms/types/options/placeholder.rst.inc @@ -71,8 +69,7 @@ type: .. include:: /reference/forms/types/options/preferred_choices.rst.inc -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc diff --git a/reference/forms/types/url.rst b/reference/forms/types/url.rst index ff4656dd6ed..e34ca991ebc 100644 --- a/reference/forms/types/url.rst +++ b/reference/forms/types/url.rst @@ -1,10 +1,10 @@ .. index:: - single: Forms; Fields; url + single: Forms; Fields; UrlType -url Field Type -============== +UrlType Field +============= -The ``url`` field is a text field that prepends the submitted value with +The ``UrlType`` field is a text field that prepends the submitted value with a given protocol (e.g. ``http://``) if the submitted value doesn't already have a protocol. @@ -26,7 +26,7 @@ have a protocol. | | - `required`_ | | | - `trim`_ | +-------------+-------------------------------------------------------------------+ -| Parent type | :doc:`text ` | +| Parent type | :doc:`TextType ` | +-------------+-------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\UrlType` | +-------------+-------------------------------------------------------------------+ @@ -46,8 +46,7 @@ the data is submitted to the form. Inherited Options ----------------- -These options inherit from the :doc:`form ` -type: +These options inherit from the :doc:`FormType `: .. include:: /reference/forms/types/options/data.rst.inc From d1314492ce84e2aad922599a8a942005c2fc79e0 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 29 Nov 2015 22:51:07 -0500 Subject: [PATCH 4/4] several other tweaks --- book/forms.rst | 5 +++-- cookbook/form/create_form_type_extension.rst | 2 +- reference/forms/types.rst | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/book/forms.rst b/book/forms.rst index 95ffabc0656..e6f3a062851 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -127,9 +127,10 @@ which HTML form tag(s) is rendered for that field. .. versionadded:: 2.8 To denote the form type, you have to use the fully qualified class name - like - TextType::class in PHP 5.5+ or ``Symfony\Component\Form\Extension\Core\Type\TextType``. + ``TextType::class`` in PHP 5.5+ or ``Symfony\Component\Form\Extension\Core\Type\TextType``. Before Symfony 2.8, you could use an alias for each type like ``text`` or - ``date``. For more details, see the `2.8 UPGRADE Log`_. + ``date``. The old alias syntax will still work until Symfony 3.0. For more details, + see the `2.8 UPGRADE Log`_. Finally, you added a submit button with a custom label for submitting the form to the server. diff --git a/cookbook/form/create_form_type_extension.rst b/cookbook/form/create_form_type_extension.rst index 11009d5922f..df290c1e4f4 100644 --- a/cookbook/form/create_form_type_extension.rst +++ b/cookbook/form/create_form_type_extension.rst @@ -113,7 +113,7 @@ tag: - + .. code-block:: php diff --git a/reference/forms/types.rst b/reference/forms/types.rst index 6dbfb54010c..9e8426de693 100644 --- a/reference/forms/types.rst +++ b/reference/forms/types.rst @@ -65,3 +65,5 @@ Supported Field Types The following field types are natively available in Symfony: .. include:: /reference/forms/types/map.rst.inc + +.. _`2.8 UPGRADE Log`: https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#form