@@ -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 }
@@ -1166,11 +1170,11 @@ easy to use in your application.
1166
1170
<?xml version =" 1.0" encoding =" UTF-8" ?>
1167
1171
<container xmlns =" http://symfony.com/schema/dic/services"
1168
1172
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" >
1170
1175
1171
1176
<services >
1172
- <service
1173
- id =" acme_demo.form.type.task"
1177
+ <service id =" app.form.type.task"
1174
1178
class =" AppBundle\Form\Type\TaskType" >
1175
1179
1176
1180
<tag name =" form.type" alias =" task" />
@@ -1183,7 +1187,7 @@ easy to use in your application.
1183
1187
// src/AppBundle/Resources/config/services.php
1184
1188
$container
1185
1189
->register(
1186
- 'acme_demo .form.type.task',
1190
+ 'app .form.type.task',
1187
1191
'AppBundle\Form\Type\TaskType'
1188
1192
)
1189
1193
->addTag('form.type', array(
@@ -1476,6 +1480,7 @@ renders the form:
1476
1480
{# app/Resources/views/default/new.html.twig #}
1477
1481
{% form_theme form 'form/fields.html.twig' %}
1478
1482
1483
+ {# or if providing multiple themes #}
1479
1484
{% form_theme form 'form/fields.html.twig' 'Form/fields2.html.twig' %}
1480
1485
1481
1486
{# ... render the form #}
@@ -1485,6 +1490,7 @@ renders the form:
1485
1490
<!-- app/Resources/views/default/new.html.php -->
1486
1491
<?php $view['form']->setTheme($form, array('form')) ?>
1487
1492
1493
+ <!-- or if providing multiple themes -->
1488
1494
<?php $view['form']->setTheme($form, array('form', 'form2')) ?>
1489
1495
1490
1496
<!-- ... render the form -->
@@ -1627,8 +1633,10 @@ file:
1627
1633
<container xmlns =" http://symfony.com/schema/dic/services"
1628
1634
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1629
1635
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" >
1632
1640
1633
1641
<twig : config >
1634
1642
<twig : form >
@@ -1713,8 +1721,10 @@ file:
1713
1721
<container xmlns =" http://symfony.com/schema/dic/services"
1714
1722
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1715
1723
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" >
1718
1728
1719
1729
<framework : config >
1720
1730
<framework : templating >
@@ -1736,7 +1746,7 @@ file:
1736
1746
'Form',
1737
1747
),
1738
1748
),
1739
- )
1749
+ ),
1740
1750
// ...
1741
1751
));
1742
1752
0 commit comments