@@ -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
542542The Form object is passed as an argument to that method (see next example).
543543You 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
565566group which is being used. If you want to validate the default constraints
566567of 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 }
@@ -1169,10 +1173,7 @@ easy to use in your application.
11691173 xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
11701174
11711175 <services >
1172- <service
1173- id =" acme_demo.form.type.task"
1174- class =" AppBundle\Form\Type\TaskType" >
1175-
1176+ <service id =" app.form.type.task" class =" AppBundle\Form\Type\TaskType" >
11761177 <tag name =" form.type" alias =" task" />
11771178 </service >
11781179 </services >
@@ -1183,7 +1184,7 @@ easy to use in your application.
11831184 // src/AppBundle/Resources/config/services.php
11841185 $container
11851186 ->register(
1186- 'acme_demo .form.type.task',
1187+ 'app .form.type.task',
11871188 'AppBundle\Form\Type\TaskType'
11881189 )
11891190 ->addTag('form.type', array(
@@ -1476,6 +1477,7 @@ renders the form:
14761477 {# app/Resources/views/default/new.html.twig #}
14771478 {% form_theme form 'form/fields.html.twig' %}
14781479
1480+ {# or if you want to use multiple themes #}
14791481 {% form_theme form 'form/fields.html.twig' 'Form/fields2.html.twig' %}
14801482
14811483 {# ... render the form #}
@@ -1485,6 +1487,7 @@ renders the form:
14851487 <!-- app/Resources/views/default/new.html.php -->
14861488 <?php $view['form']->setTheme($form, array('form')) ?>
14871489
1490+ <!-- or if you want to use multiple themes -->
14881491 <?php $view['form']->setTheme($form, array('form', 'form2')) ?>
14891492
14901493 <!-- ... render the form -->
@@ -1736,7 +1739,7 @@ file:
17361739 'Form',
17371740 ),
17381741 ),
1739- )
1742+ ),
17401743 // ...
17411744 ));
17421745
0 commit comments