From 41f7e6ff255339cef854ce10466d45700586f05f Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sun, 28 Jun 2015 16:54:10 +0200 Subject: [PATCH 01/12] Changed to HTML5's | Q | A | ------------- | --- | Doc fix? | [yes] | New docs? | [no] | Applies to | [2.3] | Fixed tickets | [] --- book/templating.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book/templating.rst b/book/templating.rst index 4447b6198a6..4261da5b3e9 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -201,7 +201,7 @@ First, build a base layout file: - + {% block title %}Test Application{% endblock %} @@ -226,7 +226,7 @@ First, build a base layout file: - + <?php $view['slots']->output('title', 'Test Application') ?> @@ -311,7 +311,7 @@ output might look like this: - + My cool blog posts From 9cd391bfc9002c40778e86988ce519fe6cb22876 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 30 Jun 2015 12:29:36 +0200 Subject: [PATCH 02/12] Note about nesting blocks and {% endblock NAME %} | Q | A | ------------- | --- | Doc fix? | [yes] | New docs? | [yes] | Applies to | [2.3] | Fixed tickets | [] --- book/templating.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/book/templating.rst b/book/templating.rst index 4261da5b3e9..1c3ac041a8d 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -370,6 +370,19 @@ When working with template inheritance, here are some tips to keep in mind: {{ parent() }} {% endblock %} +* Blocks can be nested. For better overview, you can add the block name to the + ``{% endblock %}`` tag like so: + + .. code-block:: html+jinja + + {% block foo %} + {# ... #} + {% block bar %} + {# ... #} + {% endblock bar %} + {# ... #} + {% endblock foo %} + .. index:: single: Templating; Naming conventions single: Templating; File locations From 275c079c7d6823e2829692a17c22f91b0b916340 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 2 Jul 2015 10:36:28 +0200 Subject: [PATCH 03/12] Removed unnecessary(?) YAML hint | Q | A | ------------- | --- | Doc fix? | [yes] | New docs? | [no] | Applies to | [2.3] | Fixed tickets | [] I guess it's not necessary to do anything in __construct manually - the ArrayCollection is automatically initialized when you do php app/console doctrine:generate:entities AppBundle Please double-check! --- book/doctrine.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 4df99b617be..0f149b2552b 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -953,8 +953,6 @@ To relate the ``Category`` and ``Product`` entities, start by creating a products: targetEntity: Product mappedBy: category - # don't forget to init the collection in the __construct() method - # of the entity .. code-block:: xml From a4f0318b3ac2d77c840a6fc1af6a7af4e57edcda Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 2 Jul 2015 11:23:59 +0200 Subject: [PATCH 04/12] Fixed typo | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3 | Fixed tickets | --- book/doctrine.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 0f149b2552b..9f80130f5a9 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1094,7 +1094,7 @@ table, and ``product.category_id`` column, and new foreign key: .. note:: - This task should only be really used during development. For a more robust + This command should only be used during development. For a more robust method of systematically updating your production database, read about `migrations`_. From 6e41f579f87e0ae5d16bff9e23923bed29ca26ba Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 2 Jul 2015 11:35:51 +0200 Subject: [PATCH 05/12] Another typo --- book/doctrine.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 9f80130f5a9..7925ca7a621 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1185,7 +1185,7 @@ You can also query in the other direction:: // ... } -In this case, the same things occurs: you first query out for a single ``Category`` +In this case, the same things occur: you first query out for a single ``Category`` object, and then Doctrine makes a second query to retrieve the related ``Product`` objects, but only once/if you ask for them (i.e. when you call ``->getProducts()``). The ``$products`` variable is an array of all ``Product`` objects that relate From d806300aed52c499fe4006f636951af2c939772f Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 28 Jul 2015 19:07:01 +0200 Subject: [PATCH 06/12] Typo: Removed comma | Q | A | ------------- | --- | Doc fix? | [yes] | New docs? | [no] | Applies to | [2.3] | Fixed tickets |[] --- book/forms.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/forms.rst b/book/forms.rst index d5c969b8d1c..dd1bde9c944 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -97,7 +97,7 @@ from inside a controller:: ->getForm(); return $this->render('default/new.html.twig', array( - 'form' => $form->createView(), + 'form' => $form->createView() )); } } From ebb1e741c52a36ba6b30ac62047448ec33c0e8a2 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 28 Jul 2015 21:28:32 +0200 Subject: [PATCH 07/12] Update templating.rst --- book/templating.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/templating.rst b/book/templating.rst index 1c3ac041a8d..e2c38e00111 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -371,7 +371,7 @@ When working with template inheritance, here are some tips to keep in mind: {% endblock %} * Blocks can be nested. For better overview, you can add the block name to the - ``{% endblock %}`` tag like so: + ``{% endblock %}`` tag like this: .. code-block:: html+jinja From 44d19defeaf0556c1c014fa717b35267561238cf Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 28 Jul 2015 21:47:56 +0200 Subject: [PATCH 08/12] Added example for 'required' => false | Q | A | ------------- | --- | Doc fix? | [yes] | New docs? | [no] | Applies to | [2.3] | Fixed tickets | [] --- book/forms.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/book/forms.rst b/book/forms.rst index dd1bde9c944..3ba6d1c838f 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -679,9 +679,12 @@ the documentation for each type. The most common option is the ``required`` option, which can be applied to any field. By default, the ``required`` option is set to ``true``, meaning that HTML5-ready browsers will apply client-side validation if the field - is left blank. If you don't want this behavior, either set the ``required`` - option on your field to ``false`` or - :ref:`disable HTML5 validation `. + is left blank. If you don't want this behavior, either + :ref:`disable HTML5 validation ` + or set the ``required`` option on your field to ``false``: + + ->add('dueDate', 'date', array('widget' => 'single_text', + 'required' => false)) Also note that setting the ``required`` option to ``true`` will **not** result in server-side validation to be applied. In other words, if a From d227ffba5a975c01280c78e0dd8fc7f64154cc0a Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 29 Jul 2015 12:50:53 +0200 Subject: [PATCH 09/12] Fixed typo | Q | A | ------------- | --- | Doc fix? | [yes] | New docs? | [no] | Applies to | [2.3] | Fixed tickets | [] --- book/forms.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/forms.rst b/book/forms.rst index 3ba6d1c838f..9f92b52a25d 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -923,7 +923,7 @@ specify it: Some field types have additional rendering options that can be passed to the widget. These options are documented with each type, but one common -options is ``attr``, which allows you to modify attributes on the form element. +option is ``attr``, which allows you to modify attributes on the form element. The following would add the ``task_field`` class to the rendered input text field: From 3ce46f6fd43681bb3f5e99e8b0c4994155632aaa Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 29 Jul 2015 23:29:46 +0200 Subject: [PATCH 10/12] Fixed file path "app/Resources/views/Form/fields.html.twig" didn't work for me - see next code block: "form_theme form 'AppBundle:Form:fields.html.twig'" If this change is correct, I guess it needs to be corrected multiple times on this page. --- cookbook/form/form_customization.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index 18d05ebfb1d..be5495a0c07 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -282,7 +282,7 @@ can now re-use the form customization across many templates: .. code-block:: html+twig - {# app/Resources/views/Form/fields.html.twig #} + {# src/AppBundle/Resources/views/Form/fields.html.twig #} {% block integer_widget %}
{% set type = type|default('number') %} From 2b00abe286d4a4cb1b49634b9fe35b9becf7404f Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Fri, 31 Jul 2015 13:21:45 +0200 Subject: [PATCH 11/12] Minor clarification "the form" sounded like the HTML form. | Q | A | ------------- | --- | Doc fix? | [yes] | New docs? | [no] | Applies to | [2.3] | Fixed tickets | [] --- book/forms.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/forms.rst b/book/forms.rst index 9f92b52a25d..17e19ff2310 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -212,7 +212,7 @@ Handling Form Submissions The second job of a form is to translate user-submitted data back to the properties of an object. To make this happen, the submitted data from the -user must be written into the form. Add the following functionality to your +user must be written into ``$form``. Add the following functionality to your controller:: // ... From 99cdc00a0867cc1e3a7001b4fa48f4a786b475c5 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 19 Dec 2015 16:24:17 +0100 Subject: [PATCH 12/12] Revert some changes and fix template names --- book/doctrine.rst | 2 ++ book/forms.rst | 14 ++++---- book/templating.rst | 13 ------- cookbook/form/form_customization.rst | 52 +++++++++++++++++----------- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 7925ca7a621..0d5f9141eb2 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -953,6 +953,8 @@ To relate the ``Category`` and ``Product`` entities, start by creating a products: targetEntity: Product mappedBy: category + # Don't forget to initialize the collection in + # the __construct() method of the entity .. code-block:: xml diff --git a/book/forms.rst b/book/forms.rst index 17e19ff2310..5f8c0b53ac3 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -97,7 +97,7 @@ from inside a controller:: ->getForm(); return $this->render('default/new.html.twig', array( - 'form' => $form->createView() + 'form' => $form->createView(), )); } } @@ -212,8 +212,8 @@ Handling Form Submissions The second job of a form is to translate user-submitted data back to the properties of an object. To make this happen, the submitted data from the -user must be written into ``$form``. Add the following functionality to your -controller:: +user must be written into the Form object. Add the following functionality to +your controller:: // ... use Symfony\Component\HttpFoundation\Request; @@ -681,10 +681,12 @@ the documentation for each type. that HTML5-ready browsers will apply client-side validation if the field is left blank. If you don't want this behavior, either :ref:`disable HTML5 validation ` - or set the ``required`` option on your field to ``false``: + or set the ``required`` option on your field to ``false``:: - ->add('dueDate', 'date', array('widget' => 'single_text', - 'required' => false)) + ->add('dueDate', 'date', array( + 'widget' => 'single_text', + 'required' => false + )) Also note that setting the ``required`` option to ``true`` will **not** result in server-side validation to be applied. In other words, if a diff --git a/book/templating.rst b/book/templating.rst index e2c38e00111..4261da5b3e9 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -370,19 +370,6 @@ When working with template inheritance, here are some tips to keep in mind: {{ parent() }} {% endblock %} -* Blocks can be nested. For better overview, you can add the block name to the - ``{% endblock %}`` tag like this: - - .. code-block:: html+jinja - - {% block foo %} - {# ... #} - {% block bar %} - {# ... #} - {% endblock bar %} - {# ... #} - {% endblock foo %} - .. index:: single: Templating; Naming conventions single: Templating; File locations diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index be5495a0c07..6dce09de7d6 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -243,7 +243,7 @@ directly in the template that's actually rendering the form. .. code-block:: html+twig - {% extends '::base.html.twig' %} + {% extends 'base.html.twig' %} {% form_theme form _self %} @@ -282,7 +282,7 @@ can now re-use the form customization across many templates: .. code-block:: html+twig - {# src/AppBundle/Resources/views/Form/fields.html.twig #} + {# app/Resources/views/form/fields.html.twig #} {% block integer_widget %}
{% set type = type|default('number') %} @@ -298,7 +298,7 @@ tell Symfony to use the template via the ``form_theme`` tag: .. code-block:: html+twig - {% form_theme form 'AppBundle:Form:fields.html.twig' %} + {% form_theme form 'form/fields.html.twig' %} {{ form_widget(form.age) }} @@ -314,13 +314,12 @@ name of all the templates as an array using the ``with`` keyword: .. code-block:: html+twig - {% form_theme form with ['::common.html.twig', ':Form:fields.html.twig', - 'AppBundle:Form:fields.html.twig'] %} + {% form_theme form with ['common.html.twig', 'form/fields.html.twig'] %} {# ... #} -The templates can be located at different bundles and they can even be stored -at the global ``app/Resources/views/`` directory. +The templates can also be located in different bundles, use the functional name +to reference these templates, e.g. ``AcmeFormExtraBundle:form:fields.html.twig``. Child Forms ........... @@ -329,16 +328,16 @@ You can also apply a form theme to a specific child of your form: .. code-block:: html+twig - {% form_theme form.child 'AppBundle:Form:fields.html.twig' %} + {% form_theme form.child 'form/fields.html.twig' %} This is useful when you want to have a custom theme for a nested form that's different than the one of your main form. Just specify both your themes: .. code-block:: html+twig - {% form_theme form 'AppBundle:Form:fields.html.twig' %} + {% form_theme form 'form/fields.html.twig' %} - {% form_theme form.child 'AppBundle:Form:fields_child.html.twig' %} + {% form_theme form.child 'form/fields_child.html.twig' %} .. _cookbook-form-php-theming: @@ -354,9 +353,13 @@ file in order to customize the ``integer_widget`` fragment. .. code-block:: html+php - +
- block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "number")) ?> + block( + $form, + 'form_widget_simple', + array('type' => isset($type) ? $type : "number") + ) ?>
Now that you've created the customized form template, you need to tell Symfony @@ -367,7 +370,7 @@ tell Symfony to use the theme via the ``setTheme`` helper method: .. code-block:: php - setTheme($form, array('AppBundle:Form')); ?> + setTheme($form, array(':form')); ?> widget($form['age']) ?> @@ -380,7 +383,14 @@ method: .. code-block:: php - setTheme($form['child'], 'AppBundle:Form/Child'); ?> + setTheme($form['child'], ':form'); ?> + +.. note:: + + The ``:form`` syntax is based on the functional names for templates: + ``Bundle:Directory``. As the form directory lives in the + ``app/Resources/views`` directory, the ``Bundle`` part is empty, resulting + in ``:form``. .. _cookbook-form-twig-import-base-blocks: @@ -454,8 +464,8 @@ Twig ~~~~ By using the following configuration, any customized form blocks inside the -``AppBundle:Form:fields.html.twig`` template will be used globally when a -form is rendered. +``form/fields.html.twig`` template will be used globally when a form is +rendered. .. configuration-block:: @@ -465,7 +475,7 @@ form is rendered. twig: form: resources: - - 'AppBundle:Form:fields.html.twig' + - 'form/fields.html.twig' # ... .. code-block:: xml @@ -473,7 +483,7 @@ form is rendered. - AppBundle:Form:fields.html.twig + form/fields.html.twig @@ -484,7 +494,7 @@ form is rendered. $container->loadFromExtension('twig', array( 'form' => array( 'resources' => array( - 'AppBundle:Form:fields.html.twig', + 'form/fields.html.twig', ), ), @@ -666,7 +676,7 @@ customize the ``name`` field only: .. code-block:: html+php - setTheme($form, array('AppBundle:Form')); ?> + setTheme($form, array(':form')); ?> widget($form['name']); ?> @@ -723,7 +733,7 @@ You can also override the markup for an entire field row using the same method: .. code-block:: html+php - setTheme($form, array('AppBundle:Form')); ?> + setTheme($form, array(':form')); ?> row($form['name']); ?>