8000 bug #33573 [TwigBridge] Add row_attr to all form themes (fancyweb) · symfony/symfony@81ba73c · GitHub
[go: up one dir, main page]

Skip to content

Commit 81ba73c

Browse files
bug #33573 [TwigBridge] Add row_attr to all form themes (fancyweb)
This PR was merged into the 4.3 branch. Discussion ---------- [TwigBridge] Add row_attr to all form themes | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #33552 | License | MIT | Doc PR | - The rules I applied: - Always done on the first HTML tag of the row. - Current existing row attrs (`class` or `style`) are applied unless they are defined by the `row_attr` override. They can be removed if they are explicitly set to `false`. Starting from: ``` <div class="form-group"> ``` With `row_attr: {foo: "bar"}`: ``` <div foo="bar" class="form-group"> ``` With `row_attr: {class: "ccc"}`: ``` <div class="ccc"> ``` With `row_attr: {foo: "bar", class: false}`: ``` <div foo="bar"> ``` Commits ------- dfdcbb4 [TwigBridge] Add row_attr to all form themes
2 parents 50db43f + dfdcbb4 commit 81ba73c

10 files changed

+28
-27
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ col-sm-2
2727
{%- if help is not empty -%}
2828
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
2929
{%- endif -%}
30-
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
30+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ ((not compound or force_error|default(false)) and not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>
3131
{{- form_label(form) -}}
3232
<div class="{{ block('form_group_class') }}">
3333
{{- form_widget(form, widget_attr) -}}
@@ -38,7 +38,7 @@ col-sm-2
3838
{%- endblock form_row %}
3939

4040
{% block submit_row -%}
41-
<div class="form-group">{#--#}
41+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
4242
<div class="{{ block('form_label_class') }}"></div>{#--#}
4343
<div class="{{ block('form_group_class') }}">
4444
{{- form_widget(form) -}}
@@ -47,7 +47,7 @@ col-sm-2
4747
{%- endblock submit_row %}
4848

4949
{% block reset_row -%}
50-
<div class="form-group">{#--#}
50+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
5151
<div class="{{ block('form_label_class') }}"></div>{#--#}
5252
<div class="{{ block('form_group_class') }}">
5353
{{- form_widget(form) -}}
@@ -60,7 +60,7 @@ col-sm-10
6060
{%- endblock form_group_class %}
6161

6262
{% block checkbox_row -%}
63-
<div class="form-group{% if not valid %} has-error{% endif %}">{#--#}
63+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ (not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
6464
<div class="{{ block('form_label_class') }}"></div>{#--#}
6565
<div class="{{ block('form_group_class') }}">
6666
{{- form_widget(form) -}}

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
{%- if help is not empty -%}
112112
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
113113
{%- endif -%}
114-
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
114+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ ((not compound or force_error|default(false)) and not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>
115115
{{- form_label(form) }} {# -#}
116116
{{ form_widget(form, widget_attr) }} {# -#}
117117
{{- form_help(form) -}}
@@ -120,7 +120,7 @@
120120
{%- endblock form_row %}
121121

122122
{% block button_row -%}
123-
<div class="form-group">
123+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
124124
{{- form_widget(form) -}}
125125
</div>
126126
{%- endblock button_row %}
@@ -146,14 +146,14 @@
146146
{%- endblock datetime_row %}
147147

148148
{% block checkbox_row -%}
149-
<div class="form-group{% if not valid %} has-error{% endif %}">
149+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ (not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>
150150
{{- form_widget(form) -}}
151151
{{- form_errors(form) -}}
152152
</div>
153153
{%- endblock checkbox_row %}
154154

155155
{% block radio_row -%}
156-
<div class="form-group{% if not valid %} has-error{% endif %}">
156+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ (not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>
157157
{{- form_widget(form) -}}
158158
{{- form_errors(form) -}}
159159
</div>

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ col-sm-2
2828
{%- if help is not empty -%}
2929
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
3030
{%- endif -%}
31-
<div class="form-group row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
31+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group row' ~ ((not compound or force_error|default(false)) and not valid ? ' is-invalid'))|trim})} %}{{ block('attributes') }}{% endwith %}>
3232
{{- form_label(form) -}}
3333
<div class="{{ block('form_group_class') }}">
3434
{{- form_widget(form, widget_attr) -}}
@@ -43,7 +43,7 @@ col-sm-2
4343
{%- if help is not empty -%}
4444
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
4545
{%- endif -%}
46-
<fieldset class="form-group">
46+
<fieldset{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
4747
<div class="row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
4848
{{- form_label(form) -}}
4949
<div class="{{ block('form_group_class') }}">
@@ -55,7 +55,7 @@ col-sm-2
5555
{%- endblock fieldset_form_row %}
5656

5757
{% block submit_row -%}
58-
<div class="form-group row">{#--#}
58+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group row')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
5959
<div class="{{ block('form_label_class') }}"></div>{#--#}
6060
<div class="{{ block('form_group_class') }}">
6161
{{- form_widget(form) -}}
@@ -64,7 +64,7 @@ col-sm-2
6464
{%- endblock submit_row %}
6565

6666
{% block reset_row -%}
67-
<div class="form-group row">{#--#}
67+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group row')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
6868
<div class="{{ block('form_label_class') }}"></div>{#--#}
6969
<div class="{{ block('form_group_class') }}">
7070
{{- form_widget(form) -}}
@@ -77,7 +77,7 @@ col-sm-10
7777
{%- endblock form_group_class %}
7878

7979
{% block checkbox_row -%}
80-
<div class="form-group row">{#--#}
80+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group row')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
8181
<div class="{{ block('form_label_class') }}"></div>{#--#}
8282
<div class="{{ block('form_group_class') }}">
8383
{{- form_widget(form) -}}

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@
282282
{%- if help is not empty -%}
283283
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
284284
{%- endif -%}
285-
<{{ element|default('div') }} class="form-group">
285+
<{{ element|default('div') }}{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
286286
{{- form_label(form) -}}
287287
{{- form_widget(form, widget_attr) -}}
288288
{{- form_help(form) -}}

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
{# Rows #}
188188

189189
{% block button_row -%}
190-
<div class="form-group">
190+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
191191
{{- form_widget(form) -}}
192192
</div>
193193
{%- endblock button_row %}

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
{%- if help is not empty -%}
326326
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
327327
{%- endif -%}
328-
<div {% with {attr: row_attr|default({})} %}{{ block('attributes') }}{% endwith %}>
328+
<div{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
329329
{{- form_label(form) -}}
330330
{{- form_errors(form) -}}
331331
{{- form_widget(form, widget_attr) -}}
@@ -334,7 +334,7 @@
334334
{%- endblock form_row -%}
335335

336336
{%- block button_row -%}
337-
<div {% with {attr: row_attr|default({})} %}{{ block('attributes') }}{% endwith %}>
337+
<div{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
338338
{{- form_widget(form) -}}
339339
</div>
340340
{%- endblock button_row -%}

src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{%- if help is not empty -%}
66
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
77
{%- endif -%}
8-
<tr>
8+
<tr{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
99
<td>
1010
{{- form_label(form) -}}
1111
</td>
@@ -18,7 +18,7 @@
1818
{%- endblock form_row -%}
1919

2020
{%- block button_row -%}
21-
<tr>
21+
<tr{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
2222
<td></td>
2323
<td>
2424
{{- form_widget(form) -}}
@@ -27,7 +27,8 @@
2727
{%- endblock button_row -%}
2828

2929
{%- block hidden_row -%}
30-
<tr style="display: none">
30+
{%- set style = row_attr.style is defined ? (row_attr.style ~ (row_attr.style|trim|last != ';' ? '; ')) : '' -%}
31+
<tr{% with {attr: row_attr|merge({style: (style ~ ' display: none')|trim})} %}{{ block('attributes') }}{% endwith %}>
3132
<td colspan="2">
3233
{{- form_widget(form) -}}
3334
</td>

src/Symfony/Bridge/Twig/Resources/views/Form/foundation_5_layout.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277
{%- if help is not empty -%}
278278
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
279279
{%- endif -%}
280-
<div class="row">
280+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' row')|trim})} %}{{ block('attributes') }}{% endwith %}>
281281
<div class="large-12 columns{% if (not compound or force_error|default(false)) and not valid %} error{% endif %}">
282282
{{- form_label(form) -}}
283283
{{- form_widget(form, widget_attr) -}}
@@ -308,7 +308,7 @@
308308
{%- endblock datetime_row %}
309309

310310
{% block checkbox_row -%}
311-
<div class="row">
311+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' row')|trim})} %}{{ block('attributes') }}{% endwith %}>
312312
<div class="large-12 columns{% if not valid %} error{% endif %}">
313313
{{ form_widget(form) }}
314314
{{ form_errors(form) }}
@@ -317,7 +317,7 @@
317317
{%- endblock checkbox_row %}
318318

319319
{% block radio_row -%}
320-
<div class="row">
320+
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' row')|trim})} %}{{ block('attributes') }}{% endwith %}>
321321
<div class="large-12 columns{% if not valid %} error{% endif %}">
322322
{{ form_widget(form) }}
323323
{{ form_errors(form) }}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"symfony/asset": "~3.4|~4.0",
2727
"symfony/dependency-injection": "~3.4|~4.0",
2828
"symfony/finder": "~3.4|~4.0",
29-
"symfony/form": "^4.3.4",
29+
"symfony/form": "^4.3.5",
3030
"symfony/http-foundation": "~4.3",
3131
"symfony/http-kernel": "~3.4|~4.0",
3232
"symfony/mime": "~4.3",
@@ -48,7 +48,7 @@
4848
},
4949
"conflict": {
5050
"symfony/console": "<3.4",
51-
"symfony/form": "<4.3.4",
51+
"symfony/form": "<4.3.5",
5252
"symfony/http-foundation": "<4.3",
5353
"symfony/translation": "<4.2",
5454
"symfony/workflow": "<4.3"

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"symfony/css-selector": "~3.4|~4.0",
3939
"symfony/dom-crawler": "^4.3",
4040
"symfony/polyfill-intl-icu": "~1.0",
41-
"symfony/form": "^4.3.4",
41+
"symfony/form": "^4.3.5",
4242
"symfony/expression-language": "~3.4|~4.0",
4343
"symfony/http-client": "^4.3",
4444
"symfony/mailer": "^4.3",
@@ -72,7 +72,7 @@
7272
"symfony/console": "<4.3",
7373
"symfony/dotenv": "<4.2",
7474
"symfony/dom-crawler": "<4.3",
75-
"symfony/form": "<4.3",
75+
"symfony/form": "<4.3.5",
7676
"symfony/messenger": "<4.3.6",
7777
"symfony/property-info": "<3.4",
7878
"symfony/serializer": "<4.2",

0 commit comments

Comments
 (0)
0