Skip to content

Commit 19e879b

Browse files
ifdatticxabbuh
authored andcommitted
Update forms.rst
| Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3 | Fixed tickets | Conflicts: book/forms.rst
1 parent 4cab2c6 commit 19e879b

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

book/forms.rst

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ from inside a controller::
7777
// src/AppBundle/Controller/DefaultController.php
7878
namespace AppBundle\Controller;
7979

80-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8180
use AppBundle\Entity\Task;
81+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8282
use Symfony\Component\HttpFoundation\Request;
8383

8484
class DefaultController extends Controller
@@ -542,16 +542,17 @@ This will call the static method ``determineValidationGroups()`` on the
542542
The Form object is passed as an argument to that method (see next example).
543543
You can also define whole logic inline by using a ``Closure``::
544544

545-
use Acme\AcmeBundle\Entity\Client;
545+
use AppBundle\Entity\Client;
546546
use Symfony\Component\Form\FormInterface;
547547
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
548548

549549
// ...
550550
public function setDefaultOptions(OptionsResolverInterface $resolver)
551551
{
552552
$resolver->setDefaults(array(
553-
'validation_groups' => function(FormInterface $form) {
553+
'validation_groups' => function (FormInterface $form) {
554554
$data = $form->getData();
555+
555556
if (Client::TYPE_PERSON == $data->getType()) {
556557
return array('person');
557558
}
@@ -565,16 +566,17 @@ Using the ``validation_groups`` option overrides the default validation
565566
group which is being used. If you want to validate the default constraints
566567
of the entity as well you have to adjust the option as follows::
567568

568-
use Acme\AcmeBundle\Entity\Client;
569+
use AppBundle\Entity\Client;
569570
use Symfony\Component\Form\FormInterface;
570571
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
571572

572573
// ...
573574
public function setDefaultOptions(OptionsResolverInterface $resolver)
574575
{
575576
$resolver->setDefaults(array(
576-
'validation_groups' => function(FormInterface $form) {
577+
'validation_groups' => function (FormInterface $form) {
577578
$data = $form->getData();
579+
578580
if (Client::TYPE_PERSON == $data->getType()) {
579581
return array('Default', 'person');
580582
}
@@ -1048,7 +1050,8 @@ that will house the logic for building the task form::
10481050
$builder
10491051
->add('task')
10501052
->add('dueDate', null, array('widget' => 'single_text'))
1051-
->add('save', 'submit');
1053+
->add('save', 'submit')
1054+
;
10521055
}
10531056

10541057
public function getName()
@@ -1123,7 +1126,8 @@ the choice is ultimately up to you.
11231126
$builder
11241127
->add('task')
11251128
->add('dueDate', null, array('mapped' => false))
1126-
->add('save', 'submit');
1129+
->add('save', 'submit')
1130+
;
11271131
}
11281132

11291133
Additionally, if there are any fields on the form that aren't included in
@@ -1155,7 +1159,7 @@ easy to use in your application.
11551159
11561160
# src/AppBundle/Resources/config/services.yml
11571161
services:
1158-
acme_demo.form.type.task:
1162+
app.form.type.task:
11591163
class: AppBundle\Form\Type\TaskType
11601164
tags:
11611165
- { name: form.type, alias: task }
@@ -1166,11 +1170,11 @@ easy to use in your application.
11661170
<?xml version="1.0" encoding="UTF-8" ?>
11671171
<container xmlns="http://symfony.com/schema/dic/services"
11681172
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1169-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
1173+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1174+
http://symfony.com/schema/dic/services/services-1.0.xsd">
11701175
11711176
<services>
1172-
<service
1173-
id="acme_demo.form.type.task"
1177+
<service id="app.form.type.task"
11741178
class="AppBundle\Form\Type\TaskType">
11751179
11761180
<tag name="form.type" alias="task" />
@@ -1183,7 +1187,7 @@ easy to use in your application.
11831187
// src/AppBundle/Resources/config/services.php
11841188
$container
11851189
->register(
1186-
'acme_demo.form.type.task',
1190+
'app.form.type.task',
11871191
'AppBundle\Form\Type\TaskType'
11881192
)
11891193
->addTag('form.type', array(
@@ -1476,6 +1480,7 @@ renders the form:
14761480
{# app/Resources/views/default/new.html.twig #}
14771481
{% form_theme form 'form/fields.html.twig' %}
14781482

1483+
{# or if providing multiple themes #}
14791484
{% form_theme form 'form/fields.html.twig' 'Form/fields2.html.twig' %}
14801485

14811486
{# ... render the form #}
@@ -1485,6 +1490,7 @@ renders the form:
14851490
<!-- app/Resources/views/default/new.html.php -->
14861491
<?php $view['form']->setTheme($form, array('form')) ?>
14871492

1493+
<!-- or if providing multiple themes -->
14881494
<?php $view['form']->setTheme($form, array('form', 'form2')) ?>
14891495

14901496
<!-- ... render the form -->
@@ -1627,8 +1633,10 @@ file:
16271633
<container xmlns="http://symfony.com/schema/dic/services"
16281634
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
16291635
xmlns:twig="http://symfony.com/schema/dic/twig"
1630-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
1631-
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
1636+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1637+
http://symfony.com/schema/dic/services/services-1.0.xsd
1638+
http://symfony.com/schema/dic/twig
1639+
http://symfony.com/schema/dic/twig/twig-1.0.xsd">
16321640
16331641
<twig:config>
16341642
<twig:form>
@@ -1713,8 +1721,10 @@ file:
17131721
<container xmlns="http://symfony.com/schema/dic/services"
17141722
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17151723
xmlns:framework="http://symfony.com/schema/dic/symfony"
1716-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
1717-
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1724+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1725+
http://symfony.com/schema/dic/services/services-1.0.xsd
1726+
http://symfony.com/schema/dic/symfony
1727+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
17181728
17191729
<framework:config>
17201730
<framework:templating>
@@ -1736,7 +1746,7 @@ file:
17361746
'Form',
17371747
),
17381748
),
1739-
)
1749+
),
17401750
// ...
17411751
));
17421752

0 commit comments

Comments
 (0)