Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eaf0664

Browse files
committed
Merge branch '4.1'
* 4.1: Removed the code of the PHP templates
2 parents 3ade0c8 + aa6be54 commit eaf0664

24 files changed

+371
-1026
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-
{# templates/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+
{# templates/product/new.html.twig #}
89+
<h1>Adding a new product</h1>
10090

101-
<!-- templates/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

@@ -202,17 +191,9 @@ There are some important things to consider in the code of the above controller:
202191

203192
You can use the following code to link to the PDF brochure of a product:
204193

205-
.. configuration-block::
206-
207-
.. code-block:: html+twig
208-
209-
<a href="{{ asset('uploads/brochures/' ~ product.brochure) }}">View brochure (PDF)</a>
210-
211-
.. code-block:: html+php
194+
.. code-block:: html+twig
212195

213-
<a href="<?php echo $view['assets']->getUrl('uploads/brochures/'.$product->getBrochure()) ?>">
214-
View brochure (PDF)
215-
</a>
196+
<a href="{{ asset('uploads/brochures/' ~ product.brochure) }}">View brochure (PDF)</a>
216197

217198
.. tip::
218199

doctrine/registration_form.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ With some validation added, your class may look something like this::
9393
* @ORM\Column(type="string", length=64)
9494
*/
9595
private $password;
96-
96+
9797
/**
9898
* @ORM\Column(type="array")
9999
*/
@@ -152,7 +152,7 @@ With some validation added, your class may look something like this::
152152
// You *may* need a real salt if you choose a different encoder.
153153
return null;
154154
}
155-
155+
156156
public function getRoles()
157157
{
158158
return $this->roles;

form/action_method.rst

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +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-
{# templates/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-
<!-- templates/default/new.html.php -->
128-
<?php echo $view['form']->start($form, array(
129-
'action' => $view['router']->path('target_route'),
130-
'method' => 'GET',
131-
)) ?>
120+
{# templates/default/new.html.twig #}
121+
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
132122

133123
.. note::
134124

form/create_custom_field_type.rst

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

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

158139
.. tip::
159140

form/create_form_type_extension.rst

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

219-
.. configuration-block::
220-
221-
.. code-block:: html+twig
222-
223-
{# templates/form/fields.html.twig #}
224-
{% extends 'form_div_layout.html.twig' %}
225-
226-
{% block file_widget %}
227-
{% spaceless %}
219+
.. code-block:: html+twig
228220

229-
{{ block('form_widget') }}
230-
{% if image_url is not null %}
231-
<img src="{{ asset(image_url) }}"/>
232-
{% endif %}
221+
{# templates/form/fields.html.twig #}
222+
{% extends 'form_div_layout.html.twig' %}
233223

234-
{% endspaceless %}
235-
{% endblock %}
224+
{% block file_widget %}
225+
{% spaceless %}
236226

237-
.. code-block:: html+php
227+
{{ block('form_widget') }}
228+
{% if image_url is not null %}
229+
<img src="{{ asset(image_url) }}"/>
230+
{% endif %}
238231

239-
<!-- src/Resources/file_widget.html.php -->
240-
<?php echo $view['form']->widget($form) ?>
241-
<?php if (null !== $image_url): ?>
242-
<img src="<?php echo $view['assets']->getUrl($image_url) ?>"/>
243-
<?php endif ?>
232+
{% endspaceless %}
233+
{% endblock %}
244234

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

form/dynamic_form_modification.rst

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

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

613576
The major benefit of submitting the whole form to just extract the updated
614577
``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)