Skip to content

Commit f33473f

Browse files
committed
Merge branch '2.8' into 3.4
* 2.8: Removed the code of the PHP templates
2 parents f1b9908 + 6d940aa commit f33473f

24 files changed

+372
-1048
lines changed

controller/upload_file.rst

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,16 @@ Now, update the template that renders the form to display the new ``brochure``
8383
field (the exact template code to add depends on the method used by your application
8484
to :doc:`customize form rendering </form/form_customization>`):
8585

86-
.. configuration-block::
87-
88-
.. code-block:: html+twig
89-
90-
{# app/Resources/views/product/new.html.twig #}
91-
<h1>Adding a new product</h1>
92-
93-
{{ form_start(form) }}
94-
{# ... #}
95-
96-
{{ form_row(form.brochure) }}
97-
{{ form_end(form) }}
86+
.. code-block:: html+twig
9887

99-
.. code-block:: html+php
88+
{# app/Resources/views/product/new.html.twig #}
89+
<h1>Adding a new product</h1>
10090

101-
<!-- app/Resources/views/product/new.html.php -->
102-
<h1>Adding a new product</h1>
91+
{{ form_start(form) }}
92+
{# ... #}
10393

104-
<?php echo $view['form']->start($form) ?>
105-
<?php echo $view['form']->row($form['brochure']) ?>
106-
<?php echo $view['form']->end($form) ?>
94+
{{ form_row(form.brochure) }}
95+
{{ form_end(form) }}
10796

10897
Finally, you need to update the code of the controller that handles the form::
10998

@@ -197,17 +186,9 @@ There are some important things to consider in the code of the above controller:
197186

198187
You can use the following code to link to the PDF brochure of a product:
199188

200-
.. configuration-block::
201-
202-
.. code-block:: html+twig
203-
204-
<a href="{{ asset('uploads/brochures/' ~ product.brochure) }}">View brochure (PDF)</a>
205-
206-
.. code-block:: html+php
189+
.. code-block:: html+twig
207190

208-
<a href="<?php echo $view['assets']->getUrl('uploads/brochures/'.$product->getBrochure()) ?>">
209-
View brochure (PDF)
210-
</a>
191+
<a href="{{ asset('uploads/brochures/' ~ product.brochure) }}">View brochure (PDF)</a>
211192

212193
.. tip::
213194

doctrine/registration_form.rst

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -363,34 +363,18 @@ the :ref:`user password encoding <security-encoding-user-password>` article.
363363
364364
Next, create the template:
365365

366-
.. configuration-block::
367-
368-
.. code-block:: html+twig
369-
370-
{# app/Resources/views/registration/register.html.twig #}
371-
372-
{{ form_start(form) }}
373-
{{ form_row(form.username) }}
374-
{{ form_row(form.email) }}
375-
{{ form_row(form.plainPassword.first) }}
376-
{{ form_row(form.plainPassword.second) }}
377-
378-
<button type="submit">Register!</button>
379-
{{ form_end(form) }}
380-
381-
.. code-block:: html+php
382-
383-
<!-- app/Resources/views/registration/register.html.php -->
366+
.. code-block:: html+twig
384367

385-
<?php echo $view['form']->start($form) ?>
386-
<?php echo $view['form']->row($form['username']) ?>
387-
<?php echo $view['form']->row($form['email']) ?>
368+
{# app/Resources/views/registration/register.html.twig #}
388369

389-
<?php echo $view['form']->row($form['plainPassword']['first']) ?>
390-
<?php echo $view['form']->row($form['plainPassword']['second']) ?>
370+
{{ form_start(form) }}
371+
{{ form_row(form.username) }}
372+
{{ form_row(form.email) }}
373+
{{ form_row(form.plainPassword.first) }}
374+
{{ form_row(form.plainPassword.second) }}
391375

392-
<button type="submit">Register!</button>
393-
<?php echo $view['form']->end($form) ?>
376+
<button type="submit">Register!</button>
377+
{{ form_end(form) }}
394378

395379
See :doc:`/form/form_customization` for more details.
396380

form/action_method.rst

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,10 @@ options:
115115
Finally, you can override the action and method in the template by passing them
116116
to the ``form()`` or the ``form_start()`` helper functions:
117117

118-
.. configuration-block::
119-
120-
.. code-block:: html+twig
121-
122-
{# app/Resources/views/default/new.html.twig #}
123-
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
118+
.. code-block:: html+twig
124119

125-
.. code-block:: html+php
126-
127-
<!-- app/Resources/views/default/new.html.php -->
128-
<?php echo $view['form']->start($form, array(
129-
// The path() method was introduced in Symfony 2.8. Prior to 2.8,
130-
// you had to use generate().
131-
'action' => $view['router']->path('target_route'),
132-
'method' => 'GET',
133-
)) ?>
120+
{# app/Resources/views/default/new.html.twig #}
121+
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
134122

135123
.. note::
136124

form/create_custom_field_type.rst

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -116,45 +116,26 @@ But for the sake of this example, suppose that when your field is "expanded"
116116
always render it in a ``ul`` element. In your form theme template (see above
117117
link for details), create a ``shipping_widget`` block to handle this:
118118

119-
.. configuration-block::
120-
121-
.. code-block:: html+twig
122-
123-
{# app/Resources/views/form/fields.html.twig #}
124-
{% block shipping_widget %}
125-
{% spaceless %}
126-
{% if expanded %}
127-
<ul {{ block('widget_container_attributes') }}>
128-
{% for child in form %}
129-
<li>
130-
{{ form_widget(child) }}
131-
{{ form_label(child) }}
132-
</li>
133-
{% endfor %}
134-
</ul>
135-
{% else %}
136-
{# just let the choice widget render the select tag #}
137-
{{ block('choice_widget') }}
138-
{% endif %}
139-
{% endspaceless %}
140-
{% endblock %}
141-
142-
.. code-block:: html+php
143-
144-
<!-- app/Resources/views/form/shipping_widget.html.php -->
145-
<?php if ($expanded) : ?>
146-
<ul <?php $view['form']->block($form, 'widget_container_attributes') ?>>
147-
<?php foreach ($form as $child) : ?>
148-
<li>
149-
<?php echo $view['form']->widget($child) ?>
150-
<?php echo $view['form']->label($child) ?>
151-
</li>
152-
<?php endforeach ?>
153-
</ul>
154-
<?php else : ?>
155-
<!-- just let the choice widget render the select tag -->
156-
<?php echo $view['form']->renderBlock('choice_widget') ?>
157-
<?php endif ?>
119+
.. code-block:: html+twig
120+
121+
{# app/Resources/views/form/fields.html.twig #}
122+
{% block shipping_widget %}
123+
{% spaceless %}
124+
{% if expanded %}
125+
<ul {{ block('widget_container_attributes') }}>
126+
{% for child in form %}
127+
<li>
128+
{{ form_widget(child) }}
129+
{{ form_label(child) }}
130+
</li>
131+
{% endfor %}
132+
</ul>
133+
{% else %}
134+
{# just let the choice widget render the select tag #}
135+
{{ block('choice_widget') }}
136+
{% endif %}
137+
{% endspaceless %}
138+
{% endblock %}
158139

159140
.. tip::
160141

form/create_form_type_extension.rst

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -220,31 +220,21 @@ In your extension class, you added a new variable (``image_url``), but
220220
you still need to take advantage of this new variable in your templates.
221221
Specifically, you need to override the ``file_widget`` block:
222222

223-
.. configuration-block::
224-
225-
.. code-block:: html+twig
226-
227-
{# app/Resources/fields.html.twig #}
228-
{% extends 'form_div_layout.html.twig' %}
229-
230-
{% block file_widget %}
231-
{% spaceless %}
223+
.. code-block:: html+twig
232224

233-
{{ block('form_widget') }}
234-
{% if image_url is not null %}
235-
<img src="{{ asset(image_url) }}"/>
236-
{% endif %}
225+
{# src/AppBundle/Resources/views/Form/fields.html.twig #}
226+
{% extends 'form_div_layout.html.twig' %}
237227

238-
{% endspaceless %}
239-
{% endblock %}
228+
{% block file_widget %}
229+
{% spaceless %}
240230

241-
.. code-block:: html+php
231+
{{ block('form_widget') }}
232+
{% if image_url is not null %}
233+
<img src="{{ asset(image_url) }}"/>
234+
{% endif %}
242235

243-
<!-- app/Resources/file_widget.html.php -->
244-
<?php echo $view['form']->widget($form) ?>
245-
<?php if (null !== $image_url): ?>
246-
<img src="<?php echo $view['assets']->getUrl($image_url) ?>"/>
247-
<?php endif ?>
236+
{% endspaceless %}
237+
{% endblock %}
248238

249239
Be sure to :ref:`configure this form theme template <forms-theming-global>` so that
250240
the form system sees it.

form/dynamic_form_modification.rst

Lines changed: 34 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -544,77 +544,40 @@ your application. Assume that you have a sport meetup creation controller::
544544
The associated template uses some JavaScript to update the ``position`` form
545545
field according to the current selection in the ``sport`` field:
546546

547-
.. configuration-block::
548-
549-
.. code-block:: html+twig
550-
551-
{# app/Resources/views/meetup/create.html.twig #}
552-
{{ form_start(form) }}
553-
{{ form_row(form.sport) }} {# <select id="meetup_sport" ... #}
554-
{{ form_row(form.position) }} {# <select id="meetup_position" ... #}
555-
{# ... #}
556-
{{ form_end(form) }}
557-
558-
<script>
559-
var $sport = $('#meetup_sport');
560-
// When sport gets selected ...
561-
$sport.change(function() {
562-
// ... retrieve the corresponding form.
563-
var $form = $(this).closest('form');
564-
// Simulate form data, but only include the selected sport value.
565-
var data = {};
566-
data[$sport.attr('name')] = $sport.val();
567-
// Submit data via AJAX to the form's action path.
568-
$.ajax({
569-
url : $form.attr('action'),
570-
type: $form.attr('method'),
571-
data : data,
572-
success: function(html) {
573-
// Replace current position field ...
574-
$('#meetup_position').replaceWith(
575-
// ... with the returned one from the AJAX response.
576-
$(html).find('#meetup_position')
577-
);
578-
// Position field now displays the appropriate positions.
579-
}
580-
});
581-
});
582-
</script>
583-
584-
.. code-block:: html+php
585-
586-
<!-- app/Resources/views/Meetup/create.html.php -->
587-
<?php echo $view['form']->start($form) ?>
588-
<?php echo $view['form']->row($form['sport']) ?> <!-- <select id="meetup_sport" ... -->
589-
<?php echo $view['form']->row($form['position']) ?> <!-- <select id="meetup_position" ... -->
590-
<!-- ... -->
591-
<?php echo $view['form']->end($form) ?>
592-
593-
<script>
594-
var $sport = $('#meetup_sport');
595-
// When sport gets selected ...
596-
$sport.change(function() {
597-
// ... retrieve the corresponding form.
598-
var $form = $(this).closest('form');
599-
// Simulate form data, but only include the selected sport value.
600-
var data = {};
601-
data[$sport.attr('name')] = $sport.val();
602-
// Submit data via AJAX to the form's action path.
603-
$.ajax({
604-
url : $form.attr('action'),
605-
type: $form.attr('method'),
606-
data : data,
607-
success: function(html) {
608-
// Replace current position field ...
609-
$('#meetup_position').replaceWith(
610-
// ... with the returned one from the AJAX response.
611-
$(html).find('#meetup_position')
612-
);
613-
// Position field now displays the appropriate positions.
614-
}
615-
});
616-
});
617-
</script>
547+
.. code-block:: html+twig
548+
549+
{# app/Resources/views/meetup/create.html.twig #}
550+
{{ form_start(form) }}
551+
{{ form_row(form.sport) }} {# <select id="meetup_sport" ... #}
552+
{{ form_row(form.position) }} {# <select id="meetup_position" ... #}
553+
{# ... #}
554+
{{ form_end(form) }}
555+
556+
<script>
557+
var $sport = $('#meetup_sport');
558+
// When sport gets selected ...
559+
$sport.change(function() {
560+
// ... retrieve the corresponding form.
561+
var $form = $(this).closest('form');
562+
// Simulate form data, but only include the selected sport value.
563+
var data = {};
564+
data[$sport.attr('name')] = $sport.val();
565+
// Submit data via AJAX to the form's action path.
566+
$.ajax({
567+
url : $form.attr('action'),
568+
type: $form.attr('method'),
569+
data : data,
570+
success: function(html) {
571+
// Replace current position field ...
572+
$('#meetup_position').replaceWith(
573+
// ... with the returned one from the AJAX response.
574+
$(html).find('#meetup_position')
575+
);
576+
// Position field now displays the appropriate positions.
577+
}
578+
});
579+
});
580+
</script>
618581

619582
The major benefit of submitting the whole form to just extract the updated
620583
``position`` field is that no additional server-side code is needed; all the

form/embedded.rst

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,16 @@ the ``TaskType`` class.
109109

110110
Render the ``Category`` fields in the same way as the original ``Task`` fields:
111111

112-
.. configuration-block::
112+
.. code-block:: html+twig
113113

114-
.. code-block:: html+twig
114+
{# ... #}
115115

116-
{# ... #}
116+
<h3>Category</h3>
117+
<div class="category">
118+
{{ form_row(form.category.name) }}
119+
</div>
117120

118-
<h3>Category</h3>
119-
<div class="category">
120-
{{ form_row(form.category.name) }}
121-
</div>
122-
123-
{# ... #}
124-
125-
.. code-block:: html+php
126-
127-
<!-- ... -->
128-
129-
<h3>Category</h3>
130-
<div class="category">
131-
<?php echo $view['form']->row($form['category']['name']) ?>
132-
</div>
133-
134-
<!-- ... -->
121+
{# ... #}
135122

136123
When the user submits the form, the submitted data for the ``Category`` fields
137124
are used to construct an instance of ``Category``, which is then set on the

0 commit comments

Comments
 (0)