bug #11278 Remove Spaceless Blocks From Twig Templates (chrisguitarguy)
This PR was submitted for the master branch but it was merged into the 2.4 branch instead (closes #11278).
Discussion
----------
Remove Spaceless Blocks From Twig Templates
Leaving it in can only mangle values from data bound to the form.
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #11277
| License | MIT
| Doc PR |
The tests pass here, but it doesn't seem like any tests really cover the actual rendering.
Commits
-------
793a083
Remove Spaceless Blocks From Twig Templates
This commit is contained in:
commit
a05016099b
@ -9,7 +9,7 @@
|
|||||||
{%- endblock form_widget %}
|
{%- endblock form_widget %}
|
||||||
|
|
||||||
{% block form_widget_simple -%}
|
{% block form_widget_simple -%}
|
||||||
{%- set type = type|default('text') -%}
|
{% set type = type|default('text') -%}
|
||||||
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
|
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
|
||||||
{%- endblock form_widget_simple %}
|
{%- endblock form_widget_simple %}
|
||||||
|
|
||||||
@ -44,15 +44,15 @@
|
|||||||
|
|
||||||
{% block choice_widget_expanded -%}
|
{% block choice_widget_expanded -%}
|
||||||
<div {{ block('widget_container_attributes') }}>
|
<div {{ block('widget_container_attributes') }}>
|
||||||
{% for child in form %}
|
{%- for child in form %}
|
||||||
{{- form_widget(child) -}}
|
{{- form_widget(child) -}}
|
||||||
{{- form_label(child) -}}
|
{{- form_label(child) -}}
|
||||||
{% endfor %}
|
{% endfor -%}
|
||||||
</div>
|
</div>
|
||||||
{%- endblock choice_widget_expanded %}
|
{% endblock choice_widget_expanded %}
|
||||||
|
|
||||||
{% block choice_widget_collapsed -%}
|
{% block choice_widget_collapsed -%}
|
||||||
{% if required and empty_value is none and not empty_value_in_choices and not multiple %}
|
{% if required and empty_value is none and not empty_value_in_choices and not multiple -%}
|
||||||
{% set required = false %}
|
{% set required = false %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
|
<select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
|
||||||
@ -95,20 +95,20 @@
|
|||||||
{% block datetime_widget -%}
|
{% block datetime_widget -%}
|
||||||
{% if widget == 'single_text' %}
|
{% if widget == 'single_text' %}
|
||||||
{{- block('form_widget_simple') -}}
|
{{- block('form_widget_simple') -}}
|
||||||
{% else -%}
|
{% else %}
|
||||||
<div {{ block('widget_container_attributes') }}>
|
<div {{ block('widget_container_attributes') }}>
|
||||||
{{- form_errors(form.date) -}}
|
{{- form_errors(form.date) -}}
|
||||||
{{- form_errors(form.time) -}}
|
{{- form_errors(form.time) -}}
|
||||||
{{- form_widget(form.date) -}}
|
{{- form_widget(form.date) -}}
|
||||||
{{- form_widget(form.time) -}}
|
{{- form_widget(form.time) -}}
|
||||||
</div>
|
</div>
|
||||||
{%- endif %}
|
{% endif %}
|
||||||
{%- endblock datetime_widget %}
|
{%- endblock datetime_widget %}
|
||||||
|
|
||||||
{% block date_widget -%}
|
{% block date_widget -%}
|
||||||
{% if widget == 'single_text' -%}
|
{% if widget == 'single_text' %}
|
||||||
{{ block('form_widget_simple') }}
|
{{- block('form_widget_simple') -}}
|
||||||
{%- else -%}
|
{% else -%}
|
||||||
<div {{ block('widget_container_attributes') }}>
|
<div {{ block('widget_container_attributes') }}>
|
||||||
{{- date_pattern|replace({
|
{{- date_pattern|replace({
|
||||||
'{{ year }}': form_widget(form.year),
|
'{{ year }}': form_widget(form.year),
|
||||||
@ -120,10 +120,10 @@
|
|||||||
{%- endblock date_widget %}
|
{%- endblock date_widget %}
|
||||||
|
|
||||||
{% block time_widget -%}
|
{% block time_widget -%}
|
||||||
{% if widget == 'single_text' -%}
|
{% if widget == 'single_text' %}
|
||||||
{{ block('form_widget_simple') }}
|
{{- block('form_widget_simple') -}}
|
||||||
{%- else -%}
|
{% else -%}
|
||||||
{% set vars = widget == 'text' ? { 'attr': { 'size': 1 }} : {} -%}
|
{% set vars = widget == 'text' ? { 'attr': { 'size': 1 }} : {} %}
|
||||||
<div {{ block('widget_container_attributes') }}>
|
<div {{ block('widget_container_attributes') }}>
|
||||||
{{ form_widget(form.hour, vars) }}{% if with_minutes %}:{{ form_widget(form.minute, vars) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second, vars) }}{% endif %}
|
{{ form_widget(form.hour, vars) }}{% if with_minutes %}:{{ form_widget(form.minute, vars) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second, vars) }}{% endif %}
|
||||||
</div>
|
</div>
|
||||||
@ -132,8 +132,8 @@
|
|||||||
|
|
||||||
{% block number_widget -%}
|
{% block number_widget -%}
|
||||||
{# type="number" doesn't work with floats #}
|
{# type="number" doesn't work with floats #}
|
||||||
{%- set type = type|default('text') -%}
|
{% set type = type|default('text') %}
|
||||||
{{ block('form_widget_simple') }}
|
{{- block('form_widget_simple') -}}
|
||||||
{%- endblock number_widget %}
|
{%- endblock number_widget %}
|
||||||
|
|
||||||
{% block integer_widget -%}
|
{% block integer_widget -%}
|
||||||
@ -146,33 +146,33 @@
|
|||||||
{%- endblock money_widget %}
|
{%- endblock money_widget %}
|
||||||
|
|
||||||
{% block url_widget -%}
|
{% block url_widget -%}
|
||||||
{% set type = type|default('url') -%}
|
{% set type = type|default('url') %}
|
||||||
{{ block('form_widget_simple') }}
|
{{- block('form_widget_simple') -}}
|
||||||
{%- endblock url_widget %}
|
{%- endblock url_widget %}
|
||||||
|
|
||||||
{% block search_widget -%}
|
{% block search_widget -%}
|
||||||
{% set type = type|default('search') -%}
|
{% set type = type|default('search') %}
|
||||||
{{ block('form_widget_simple') }}
|
{{- block('form_widget_simple') -}}
|
||||||
{%- endblock search_widget %}
|
{%- endblock search_widget %}
|
||||||
|
|
||||||
{% block percent_widget -%}
|
{% block percent_widget -%}
|
||||||
{% set type = type|default('text') -%}
|
{% set type = type|default('text') %}
|
||||||
{{ block('form_widget_simple') }} %
|
{{- block('form_widget_simple') -}} %
|
||||||
{%- endblock percent_widget %}
|
{%- endblock percent_widget %}
|
||||||
|
|
||||||
{% block password_widget -%}
|
{% block password_widget -%}
|
||||||
{% set type = type|default('password') -%}
|
{% set type = type|default('password') %}
|
||||||
{{ block('form_widget_simple') }}
|
{{ block('form_widget_simple') }}
|
||||||
{%- endblock password_widget %}
|
{%- endblock password_widget %}
|
||||||
|
|
||||||
{% block hidden_widget -%}
|
{% block hidden_widget -%}
|
||||||
{% set type = type|default('hidden') -%}
|
{% set type = type|default('hidden') %}
|
||||||
{{ block('form_widget_simple') }}
|
{{- block('form_widget_simple') -}}
|
||||||
{%- endblock hidden_widget %}
|
{%- endblock hidden_widget -%}
|
||||||
|
|
||||||
{% block email_widget -%}
|
{% block email_widget -%}
|
||||||
{% set type = type|default('email') -%}
|
{% set type = type|default('email') %}
|
||||||
{{ block('form_widget_simple') }}
|
{{- block('form_widget_simple') -}}
|
||||||
{%- endblock email_widget %}
|
{%- endblock email_widget %}
|
||||||
|
|
||||||
{% block button_widget -%}
|
{% block button_widget -%}
|
||||||
@ -183,26 +183,26 @@
|
|||||||
{%- endblock button_widget %}
|
{%- endblock button_widget %}
|
||||||
|
|
||||||
{% block submit_widget -%}
|
{% block submit_widget -%}
|
||||||
{% set type = type|default('submit') -%}
|
{% set type = type|default('submit') %}
|
||||||
{{ block('button_widget') }}
|
{{- block('button_widget') -}}
|
||||||
{%- endblock submit_widget %}
|
{%- endblock submit_widget %}
|
||||||
|
|
||||||
{% block reset_widget -%}
|
{% block reset_widget -%}
|
||||||
{% set type = type|default('reset') -%}
|
{% set type = type|default('reset') %}
|
||||||
{{ block('button_widget') }}
|
{{- block('button_widget') -}}
|
||||||
{%- endblock reset_widget %}
|
{%- endblock reset_widget %}
|
||||||
|
|
||||||
{# Labels #}
|
{# Labels #}
|
||||||
|
|
||||||
{% block form_label -%}
|
{% block form_label -%}
|
||||||
{% if label is not sameas(false) %}
|
{% if label is not sameas(false) -%}
|
||||||
{%- if not compound -%}
|
{% if not compound -%}
|
||||||
{% set label_attr = label_attr|merge({'for': id}) %}
|
{% set label_attr = label_attr|merge({'for': id}) %}
|
||||||
{%- endif -%}
|
{%- endif %}
|
||||||
{%- if required -%}
|
{% if required -%}
|
||||||
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
|
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
|
||||||
{%- endif -%}
|
{%- endif %}
|
||||||
{%- if label is empty -%}
|
{% if label is empty -%}
|
||||||
{% set label = name|humanize %}
|
{% set label = name|humanize %}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
|
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
|
||||||
@ -218,7 +218,7 @@
|
|||||||
No need to render the errors here, as all errors are mapped
|
No need to render the errors here, as all errors are mapped
|
||||||
to the first child (see RepeatedTypeValidatorExtension).
|
to the first child (see RepeatedTypeValidatorExtension).
|
||||||
#}
|
#}
|
||||||
{{- block('form_rows') }}
|
{{- block('form_rows') -}}
|
||||||
{%- endblock repeated_row %}
|
{%- endblock repeated_row %}
|
||||||
|
|
||||||
{% block form_row -%}
|
{% block form_row -%}
|
||||||
@ -253,17 +253,17 @@
|
|||||||
{% set form_method = method %}
|
{% set form_method = method %}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{% set form_method = "POST" %}
|
{% set form_method = "POST" %}
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
<form name="{{ form.vars.name }}" method="{{ form_method|lower }}" action="{{ action }}"{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
|
<form name="{{ form.vars.name }}" method="{{ form_method|lower }}" action="{{ action }}"{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
|
||||||
{% if form_method != method %}
|
{%- if form_method != method -%}
|
||||||
<input type="hidden" name="_method" value="{{ method }}" />
|
<input type="hidden" name="_method" value="{{ method }}" />
|
||||||
{%- endif %}
|
{%- endif -%}
|
||||||
{%- endblock form_start %}
|
{%- endblock form_start %}
|
||||||
|
|
||||||
{% block form_end -%}
|
{% block form_end -%}
|
||||||
{% if not render_rest is defined or render_rest -%}
|
{% if not render_rest is defined or render_rest %}
|
||||||
{{ form_rest(form) }}
|
{{- form_rest(form) -}}
|
||||||
{%- endif -%}
|
{% endif -%}
|
||||||
</form>
|
</form>
|
||||||
{%- endblock form_end %}
|
{%- endblock form_end %}
|
||||||
|
|
||||||
@ -283,18 +283,18 @@
|
|||||||
|
|
||||||
{% block form_rest -%}
|
{% block form_rest -%}
|
||||||
{% for child in form -%}
|
{% for child in form -%}
|
||||||
{% if not child.rendered -%}
|
{% if not child.rendered %}
|
||||||
{{ form_row(child) }}
|
{{- form_row(child) -}}
|
||||||
{%- endif %}
|
{% endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- endblock form_rest %}
|
{% endblock form_rest %}
|
||||||
|
|
||||||
{# Support #}
|
{# Support #}
|
||||||
|
|
||||||
{% block form_rows -%}
|
{% block form_rows -%}
|
||||||
{% for child in form -%}
|
{% for child in form %}
|
||||||
{{ form_row(child) }}
|
{{- form_row(child) -}}
|
||||||
{%- endfor %}
|
{% endfor %}
|
||||||
{%- endblock form_rows %}
|
{%- endblock form_rows %}
|
||||||
|
|
||||||
{% block widget_attributes -%}
|
{% block widget_attributes -%}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
{{- form_widget(form) -}}
|
{{- form_widget(form) -}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{%- endblock button_row %}
|
{% endblock button_row %}
|
||||||
|
|
||||||
{% block hidden_row -%}
|
{% block hidden_row -%}
|
||||||
<tr style="display: none">
|
<tr style="display: none">
|
||||||
@ -27,11 +27,11 @@
|
|||||||
{{- form_widget(form) -}}
|
{{- form_widget(form) -}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{%- endblock hidden_row %}
|
{% endblock hidden_row %}
|
||||||
|
|
||||||
{% block form_widget_compound -%}
|
{% block form_widget_compound -%}
|
||||||
<table {{ block('widget_container_attributes') }}>
|
<table {{ block('widget_container_attributes') }}>
|
||||||
{% if form.parent is empty and errors|length > 0 -%}
|
{%- if form.parent is empty and errors|length > 0 -%}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
{{- form_errors(form) -}}
|
{{- form_errors(form) -}}
|
||||||
|
@ -756,16 +756,4 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
|
|||||||
// foo="foo"
|
// foo="foo"
|
||||||
$this->assertContains('<div id="form" foo="foo">', $html);
|
$this->assertContains('<div id="form" foo="foo">', $html);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWidgetContainerAttributeHiddenIfFalse()
|
|
||||||
{
|
|
||||||
$form = $this->factory->createNamed('form', 'form', null, array(
|
|
||||||
'attr' => array('foo' => false),
|
|
||||||
));
|
|
||||||
|
|
||||||
$html = $this->renderWidget($form->createView());
|
|
||||||
|
|
||||||
// no foo
|
|
||||||
$this->assertContains('<div id="form">', $html);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1931,8 +1931,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
|||||||
|
|
||||||
$html = $this->renderWidget($form->createView());
|
$html = $this->renderWidget($form->createView());
|
||||||
|
|
||||||
// no foo
|
$this->assertNotContains('foo="', $html);
|
||||||
$this->assertSame('<input type="text" id="text" name="text" required="required" value="value" />', $html);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testButtonAttributes()
|
public function testButtonAttributes()
|
||||||
@ -1968,7 +1967,38 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
|||||||
|
|
||||||
$html = $this->renderWidget($form->createView());
|
$html = $this->renderWidget($form->createView());
|
||||||
|
|
||||||
|
$this->assertNotContains('foo="', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTextareaWithWhitespaceOnlyContentRetainsValue()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createNamed('textarea', 'textarea', ' ');
|
||||||
|
|
||||||
|
$html = $this->renderWidget($form->createView());
|
||||||
|
|
||||||
|
$this->assertContains('> </textarea>', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTextareaWithWhitespaceOnlyContentRetainsValueWhenRenderingForm()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createBuilder('form', array('textarea' => ' '))
|
||||||
|
->add('textarea', 'textarea')
|
||||||
|
->getForm();
|
||||||
|
|
||||||
|
$html = $this->renderForm($form->createView());
|
||||||
|
|
||||||
|
$this->assertContains('> </textarea>', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWidgetContainerAttributeHiddenIfFalse()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createNamed('form', 'form', null, array(
|
||||||
|
'attr' => array('foo' => false),
|
||||||
|
));
|
||||||
|
|
||||||
|
$html = $this->renderWidget($form->createView());
|
||||||
|
|
||||||
// no foo
|
// no foo
|
||||||
$this->assertSame('<button type="button" id="button" name="button">[trans]Button[/trans]</button>', $html);
|
$this->assertNotContains('foo="', $html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -533,16 +533,4 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
|
|||||||
// foo="foo"
|
// foo="foo"
|
||||||
$this->assertContains('<table id="form" foo="foo">', $html);
|
$this->assertContains('<table id="form" foo="foo">', $html);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWidgetContainerAttributeHiddenIfFalse()
|
|
||||||
{
|
|
||||||
$form = $this->factory->createNamed('form', 'form', null, array(
|
|
||||||
'attr' => array('foo' => false),
|
|
||||||
));
|
|
||||||
|
|
||||||
$html = $this->renderWidget($form->createView());
|
|
||||||
|
|
||||||
// no foo
|
|
||||||
$this->assertContains('<table id="form">', $html);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user