diff --git a/book/forms.rst b/book/forms.rst
index b493c2c5cf5..38186bba172 100644
--- a/book/forms.rst
+++ b/book/forms.rst
@@ -77,8 +77,8 @@ from inside a controller::
// src/AppBundle/Controller/DefaultController.php
namespace AppBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Entity\Task;
+ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
@@ -542,7 +542,7 @@ This will call the static method ``determineValidationGroups()`` on the
The Form object is passed as an argument to that method (see next example).
You can also define whole logic inline by using a ``Closure``::
- use Acme\AcmeBundle\Entity\Client;
+ use AppBundle\Entity\Client;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@@ -550,8 +550,9 @@ You can also define whole logic inline by using a ``Closure``::
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
- 'validation_groups' => function(FormInterface $form) {
+ 'validation_groups' => function (FormInterface $form) {
$data = $form->getData();
+
if (Client::TYPE_PERSON == $data->getType()) {
return array('person');
}
@@ -565,7 +566,7 @@ Using the ``validation_groups`` option overrides the default validation
group which is being used. If you want to validate the default constraints
of the entity as well you have to adjust the option as follows::
- use Acme\AcmeBundle\Entity\Client;
+ use AppBundle\Entity\Client;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@@ -573,8 +574,9 @@ of the entity as well you have to adjust the option as follows::
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
- 'validation_groups' => function(FormInterface $form) {
+ 'validation_groups' => function (FormInterface $form) {
$data = $form->getData();
+
if (Client::TYPE_PERSON == $data->getType()) {
return array('Default', 'person');
}
@@ -1048,7 +1050,8 @@ that will house the logic for building the task form::
$builder
->add('task')
->add('dueDate', null, array('widget' => 'single_text'))
- ->add('save', 'submit');
+ ->add('save', 'submit')
+ ;
}
public function getName()
@@ -1123,7 +1126,8 @@ the choice is ultimately up to you.
$builder
->add('task')
->add('dueDate', null, array('mapped' => false))
- ->add('save', 'submit');
+ ->add('save', 'submit')
+ ;
}
Additionally, if there are any fields on the form that aren't included in
@@ -1155,7 +1159,7 @@ easy to use in your application.
# src/AppBundle/Resources/config/services.yml
services:
- acme_demo.form.type.task:
+ app.form.type.task:
class: AppBundle\Form\Type\TaskType
tags:
- { name: form.type, alias: task }
@@ -1169,10 +1173,7 @@ easy to use in your application.
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">