Skip to content

Commit

Permalink
Revert some changes and fix template names
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Dec 19, 2015
1 parent 2b00abe commit 99cdc00
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
2 changes: 2 additions & 0 deletions book/doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ from inside a controller::
->getForm();

return $this->render('default/new.html.twig', array(
'form' => $form->createView()
'form' => $form->createView(),
));
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 <book-forms-html5-validation-disable>`
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
Expand Down
13 changes: 0 additions & 13 deletions book/templating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 31 additions & 21 deletions cookbook/form/form_customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down Expand Up @@ -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 %}
<div class="integer_widget">
{% set type = type|default('number') %}
Expand All @@ -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) }}

Expand All @@ -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
...........
Expand All @@ -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:

Expand All @@ -354,9 +353,13 @@ file in order to customize the ``integer_widget`` fragment.

.. code-block:: html+php

<!-- app/Resources/views/Form/integer_widget.html.php -->
<!-- app/Resources/views/form/integer_widget.html.php -->
<div class="integer_widget">
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>
<?php echo $view['form']->block(
$form,
'form_widget_simple',
array('type' => isset($type) ? $type : "number")
) ?>
</div>

Now that you've created the customized form template, you need to tell Symfony
Expand All @@ -367,7 +370,7 @@ tell Symfony to use the theme via the ``setTheme`` helper method:

.. code-block:: php
<?php $view['form']->setTheme($form, array('AppBundle:Form')); ?>
<?php $view['form']->setTheme($form, array(':form')); ?>
<?php $view['form']->widget($form['age']) ?>
Expand All @@ -380,7 +383,14 @@ method:

.. code-block:: php
<?php $view['form']->setTheme($form['child'], 'AppBundle:Form/Child'); ?>
<?php $view['form']->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:

Expand Down Expand Up @@ -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::

Expand All @@ -465,15 +475,15 @@ form is rendered.
twig:
form:
resources:
- 'AppBundle:Form:fields.html.twig'
- 'form/fields.html.twig'
# ...
.. code-block:: xml
<!-- app/config/config.xml -->
<twig:config>
<twig:form>
<resource>AppBundle:Form:fields.html.twig</resource>
<resource>form/fields.html.twig</resource>
</twig:form>
<!-- ... -->
</twig:config>
Expand All @@ -484,7 +494,7 @@ form is rendered.
$container->loadFromExtension('twig', array(
'form' => array(
'resources' => array(
'AppBundle:Form:fields.html.twig',
'form/fields.html.twig',
),
),
Expand Down Expand Up @@ -666,7 +676,7 @@ customize the ``name`` field only:
.. code-block:: html+php

<!-- Main template -->
<?php echo $view['form']->setTheme($form, array('AppBundle:Form')); ?>
<?php echo $view['form']->setTheme($form, array(':form')); ?>

<?php echo $view['form']->widget($form['name']); ?>

Expand Down Expand Up @@ -723,7 +733,7 @@ You can also override the markup for an entire field row using the same method:
.. code-block:: html+php

<!-- Main template -->
<?php echo $view['form']->setTheme($form, array('AppBundle:Form')); ?>
<?php echo $view['form']->setTheme($form, array(':form')); ?>

<?php echo $view['form']->row($form['name']); ?>

Expand Down

0 comments on commit 99cdc00

Please sign in to comment.