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"> - - + @@ -1183,7 +1184,7 @@ easy to use in your application. // src/AppBundle/Resources/config/services.php $container ->register( - 'acme_demo.form.type.task', + 'app.form.type.task', 'AppBundle\Form\Type\TaskType' ) ->addTag('form.type', array( @@ -1476,6 +1477,7 @@ renders the form: {# app/Resources/views/default/new.html.twig #} {% form_theme form 'form/fields.html.twig' %} + {# or if you want to use multiple themes #} {% form_theme form 'form/fields.html.twig' 'Form/fields2.html.twig' %} {# ... render the form #} @@ -1485,6 +1487,7 @@ renders the form: setTheme($form, array('form')) ?> + setTheme($form, array('form', 'form2')) ?> @@ -1736,7 +1739,7 @@ file: 'Form', ), ), - ) + ), // ... )); diff --git a/book/templating.rst b/book/templating.rst index 895ce6de720..869d3aa7575 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -135,7 +135,7 @@ Throughout this chapter, template examples will be shown in both Twig and PHP. web designers everywhere. Twig can also do things that PHP can't, such as whitespace control, - sandboxing, automatic HTML escaping, manual contextual output escaping, + sandboxing, automatic HTML escaping, manual contextual output escaping, and the inclusion of custom functions and filters that only affect templates. Twig contains little features that make writing templates easier and more concise. Take the following example, which combines a loop with a logical ``if`` @@ -206,8 +206,8 @@ First, build a base layout file: @@ -663,7 +663,7 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**): {# ... #} @@ -676,7 +676,7 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**):