diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig index 478de622da43..f0c4626daf45 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig @@ -8,14 +8,12 @@ {# Labels #} {% block form_label -%} -{% spaceless %} - {% if label is same as(false) %} + {%- if label is same as(false) -%}
- {% else %} - {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) %} + {%- else -%} + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) -%} {{- parent() -}} - {% endif %} -{% endspaceless %} + {%- endif -%} {%- endblock form_label %} {% block form_label_class -%} @@ -35,27 +33,33 @@ col-sm-2 {%- endblock form_row %} {% block submit_row -%} -{% spaceless %} -
-
+
{#--#} +
{#--#}
- {{ form_widget(form) }} -
+ {{- form_widget(form) -}} +
{#--#}
-{% endspaceless %} -{% endblock submit_row %} +{%- endblock submit_row %} {% block reset_row -%} -{% spaceless %} -
-
+
{#--#} +
{#--#}
- {{ form_widget(form) }} -
+ {{- form_widget(form) -}} +
{#--#}
-{% endspaceless %} -{% endblock reset_row %} +{%- endblock reset_row %} {% block form_group_class -%} col-sm-10 {%- endblock form_group_class %} + +{% block checkbox_row -%} +
{#--#} +
{#--#} +
+ {{- form_widget(form) -}} + {{- form_errors(form) -}} +
{#--#} +
+{%- endblock checkbox_row %} \ No newline at end of file diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig index 1601684b1a8f..64fc2a210ee3 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig @@ -10,7 +10,7 @@ {%- endblock form_widget_simple %} {% block button_widget -%} - {% set attr = attr|merge({class: (attr.class|default('btn-default') ~ ' btn')|trim}) %} + {%- set attr = attr|merge({class: (attr.class|default('btn-default') ~ ' btn')|trim}) -%} {{- parent() -}} {%- endblock button_widget %} @@ -22,18 +22,18 @@
{{- form_label(form, null, { widget: parent() }) -}}
- {%- endif %} + {%- endif -%} {%- endblock checkbox_widget %} {% block radio_widget -%} {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%} - {% if 'radio-inline' in parent_label_class %} + {%- if 'radio-inline' in parent_label_class -%} {{- form_label(form, null, { widget: parent() }) -}} - {% else -%} + {%- else -%}
{{- form_label(form, null, { widget: parent() }) -}}
- {%- endif %} + {%- endif -%} {%- endblock radio_widget %} {# Labels #} @@ -61,30 +61,30 @@ {{- block('checkbox_radio_label') -}} {%- endblock radio_label %} -{% block checkbox_radio_label %} +{% block checkbox_radio_label -%} {# Do not display the label if widget is not defined in order to prevent double label rendering #} - {% if widget is defined %} - {% if required %} - {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %} - {% endif %} - {% if parent_label_class is defined %} - {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) %} - {% endif %} - {% if label is not same as(false) and label is empty %} + {%- if widget is defined -%} + {%- if required -%} + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%} + {%- endif -%} + {%- if parent_label_class is defined -%} + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) -%} + {%- endif -%} + {%- if label is not same as(false) and label is empty -%} {%- if label_format is not empty -%} - {% set label = label_format|replace({ + {%- set label = label_format|replace({ '%name%': name, '%id%': id, - }) %} + }) -%} {%- else -%} {% set label = name|humanize %} {%- endif -%} - {% endif %} + {%- endif -%} {{- widget|raw }} {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}} - {% endif %} -{% endblock checkbox_radio_label %} + {%- endif -%} +{%- endblock checkbox_radio_label %} {# Rows #} @@ -123,15 +123,10 @@ {%- endblock datetime_row %} {% block checkbox_row -%} -{% spaceless %}
-
-
- {{- form_widget(form) -}} - {{- form_errors(form) -}} -
+ {{- form_widget(form) -}} + {{- form_errors(form) -}}
-{% endspaceless %} {%- endblock checkbox_row %} {% block radio_row -%} diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig index 32b4944bab3d..0f0a0953282d 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig @@ -47,23 +47,33 @@ col-sm-2 {%- endblock fieldset_form_row %} {% block submit_row -%} -
-
+
{#--#} +
{#--#}
{{- form_widget(form) -}} -
+
{#--#}
{%- endblock submit_row %} {% block reset_row -%} -
-
+
{#--#} +
{#--#}
{{- form_widget(form) -}} -
+
{#--#}
{%- endblock reset_row %} {% block form_group_class -%} col-sm-10 {%- endblock form_group_class %} + +{% block checkbox_row -%} +
{#--#} +
{#--#} +
+ {{- form_widget(form) -}} + {{- form_errors(form) -}} +
{#--#} +
+{%- endblock checkbox_row %} \ No newline at end of file diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig index f9cb62209daf..2407b16d9b99 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig @@ -24,9 +24,9 @@ {% block checkbox_widget -%} {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%} {%- set attr = attr|merge({class: attr.class|default('form-check-input')}) -%} - {%- if 'checkbox-inline' in parent_label_class -%} + {% if 'checkbox-inline' in parent_label_class %} {{- form_label(form, null, { widget: parent() }) -}} - {%- else -%} + {% else -%}
{{- form_label(form, null, { widget: parent() }) -}}
diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 33ac7d5849c7..320440fab05e 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -24,7 +24,7 @@ "symfony/asset": "~2.8|~3.0|~4.0", "symfony/dependency-injection": "~2.8|~3.0|~4.0", "symfony/finder": "~2.8|~3.0|~4.0", - "symfony/form": "~3.4|~4.0", + "symfony/form": "~3.4-beta2|~4.0", "symfony/http-foundation": "^3.3.11|~4.0", "symfony/http-kernel": "~3.2|~4.0", "symfony/polyfill-intl-icu": "~1.0", diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php index 1273fa505bd2..04b5b5836c65 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php @@ -154,4 +154,13 @@ public function testStartTagWithExtraAttributes() $this->assertSame('
', $html); } + + public function testCheckboxRow() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType'); + $view = $form->createView(); + $html = $this->renderRow($view, array('label' => 'foo')); + + $this->assertMatchesXpath($html, '/div[@class="form-group"]/div[@class="col-sm-2" or @class="col-sm-10"]', 2); + } } diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php index 990fffbe9468..2833de7d91de 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php @@ -26,8 +26,8 @@ public function testLabelOnForm() $html = $this->renderLabel($view); $this->assertMatchesXpath($html, -'/label - [@class="col-form-label col-sm-2 form-control-label required"] +'/legend + [@class="col-form-label col-sm-2 col-form-legend required"] [.="[trans]Name[/trans]"] ' ); @@ -118,7 +118,7 @@ public function testLegendOnExpandedType() $this->assertMatchesXpath($html, '/legend - [@class="col-sm-2 col-form-legend form-control-label required"] + [@class="col-sm-2 col-form-legend required"] [.="[trans]Custom label[/trans]"] ' ); @@ -178,4 +178,13 @@ public function testStartTagWithExtraAttributes() $this->assertSame('', $html); } + + public function testCheckboxRow() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType'); + $view = $form->createView(); + $html = $this->renderRow($view, array('label' => 'foo')); + + $this->assertMatchesXpath($html, '/div[@class="form-group row"]/div[@class="col-sm-2" or @class="col-sm-10"]', 2); + } } diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php index 35bd1203b3f8..84f93cc33203 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php @@ -28,8 +28,8 @@ public function testLabelOnForm() $html = $this->renderLabel($view); $this->assertMatchesXpath($html, -'/label - [@class="form-control-label required"] +'/legend + [@class="col-form-legend required"] [.="[trans]Name[/trans]"] ' ); @@ -120,7 +120,7 @@ public function testLegendOnExpandedType() $this->assertMatchesXpath($html, '/legend - [@class="col-form-legend form-control-label required"] + [@class="col-form-legend required"] [.="[trans]Custom label[/trans]"] ' );