@@ -77,8 +77,8 @@ from inside a controller::
77
77
// src/AppBundle/Controller/DefaultController.php
78
78
namespace AppBundle\Controller;
79
79
80
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
81
80
use AppBundle\Entity\Task;
81
+ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
82
82
use Symfony\Component\HttpFoundation\Request;
83
83
84
84
class DefaultController extends Controller
@@ -542,16 +542,17 @@ This will call the static method ``determineValidationGroups()`` on the
542
542
The Form object is passed as an argument to that method (see next example).
543
543
You can also define whole logic inline by using a ``Closure ``::
544
544
545
- use Acme\AcmeBundle \Entity\Client;
545
+ use AppBundle \Entity\Client;
546
546
use Symfony\Component\Form\FormInterface;
547
547
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
548
548
549
549
// ...
550
550
public function setDefaultOptions(OptionsResolverInterface $resolver)
551
551
{
552
552
$resolver->setDefaults(array(
553
- 'validation_groups' => function(FormInterface $form) {
553
+ 'validation_groups' => function (FormInterface $form) {
554
554
$data = $form->getData();
555
+
555
556
if (Client::TYPE_PERSON == $data->getType()) {
556
557
return array('person');
557
558
}
@@ -565,16 +566,17 @@ Using the ``validation_groups`` option overrides the default validation
565
566
group which is being used. If you want to validate the default constraints
566
567
of the entity as well you have to adjust the option as follows::
567
568
568
- use Acme\AcmeBundle \Entity\Client;
569
+ use AppBundle \Entity\Client;
569
570
use Symfony\Component\Form\FormInterface;
570
571
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
571
572
572
573
// ...
573
574
public function setDefaultOptions(OptionsResolverInterface $resolver)
574
575
{
575
576
$resolver->setDefaults(array(
576
- 'validation_groups' => function(FormInterface $form) {
577
+ 'validation_groups' => function (FormInterface $form) {
577
578
$data = $form->getData();
579
+
578
580
if (Client::TYPE_PERSON == $data->getType()) {
579
581
return array('Default', 'person');
580
582
}
@@ -1048,7 +1050,8 @@ that will house the logic for building the task form::
1048
1050
$builder
1049
1051
->add('task')
1050
1052
->add('dueDate', null, array('widget' => 'single_text'))
1051
- ->add('save', 'submit');
1053
+ ->add('save', 'submit')
1054
+ ;
1052
1055
}
1053
1056
1054
1057
public function getName()
@@ -1123,7 +1126,8 @@ the choice is ultimately up to you.
1123
1126
$builder
1124
1127
->add('task')
1125
1128
->add('dueDate', null, array('mapped' => false))
1126
- ->add('save', 'submit');
1129
+ ->add('save', 'submit')
1130
+ ;
1127
1131
}
1128
1132
1129
1133
Additionally, if there are any fields on the form that aren't included in
@@ -1155,7 +1159,7 @@ easy to use in your application.
1155
1159
1156
1160
# src/AppBundle/Resources/config/services.yml
1157
1161
services :
1158
- acme_demo .form.type.task :
1162
+ app .form.type.task :
1159
1163
class : AppBundle\Form\Type\TaskType
1160
1164
tags :
1161
1165
- { name: form.type, alias: task }
@@ -1169,10 +1173,7 @@ easy to use in your application.
1169
1173
xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
1170
1174
1171
1175
<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" >
1176
1177
<tag name =" form.type" alias =" task" />
1177
1178
</service >
1178
1179
</services >
@@ -1183,7 +1184,7 @@ easy to use in your application.
1183
1184
// src/AppBundle/Resources/config/services.php
1184
1185
$container
1185
1186
->register(
1186
- 'acme_demo .form.type.task',
1187
+ 'app .form.type.task',
1187
1188
'AppBundle\Form\Type\TaskType'
1188
1189
)
1189
1190
->addTag('form.type', array(
@@ -1476,6 +1477,7 @@ renders the form:
1476
1477
{# app/Resources/views/default/new.html.twig #}
1477
1478
{% form_theme form 'form/fields.html.twig' %}
1478
1479
1480
+ {# or if you want to use multiple themes #}
1479
1481
{% form_theme form 'form/fields.html.twig' 'Form/fields2.html.twig' %}
1480
1482
1481
1483
{# ... render the form #}
@@ -1485,6 +1487,7 @@ renders the form:
1485
1487
<!-- app/Resources/views/default/new.html.php -->
1486
1488
<?php $view['form']->setTheme($form, array('form')) ?>
1487
1489
1490
+ <!-- or if you want to use multiple themes -->
1488
1491
<?php $view['form']->setTheme($form, array('form', 'form2')) ?>
1489
1492
1490
1493
<!-- ... render the form -->
@@ -1736,7 +1739,7 @@ file:
1736
1739
'Form',
1737
1740
),
1738
1741
),
1739
- )
1742
+ ),
1740
1743
// ...
1741
1744
));
1742
1745
0 commit comments