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
-------

dfdcbb401e [TwigBridge] Add row_attr to all form themes
This commit is contained in:
Nicolas Grekas 2019-11-28 12:39:15 +01:00
commit 81ba73cb7b
10 changed files with 28 additions and 27 deletions

View File

@ -27,7 +27,7 @@ col-sm-2
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<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 %}>
{{- form_label(form) -}}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form, widget_attr) -}}
@ -38,7 +38,7 @@ col-sm-2
{%- endblock form_row %}
{% block submit_row -%}
<div class="form-group">{#--#}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
<div class="{{ block('form_label_class') }}"></div>{#--#}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
@ -47,7 +47,7 @@ col-sm-2
{%- endblock submit_row %}
{% block reset_row -%}
<div class="form-group">{#--#}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
<div class="{{ block('form_label_class') }}"></div>{#--#}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
@ -60,7 +60,7 @@ col-sm-10
{%- endblock form_group_class %}
{% block checkbox_row -%}
<div class="form-group{% if not valid %} has-error{% endif %}">{#--#}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ (not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
<div class="{{ block('form_label_class') }}"></div>{#--#}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}

View File

@ -111,7 +111,7 @@
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<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 %}>
{{- form_label(form) }} {# -#}
{{ form_widget(form, widget_attr) }} {# -#}
{{- form_help(form) -}}
@ -120,7 +120,7 @@
{%- endblock form_row %}
{% block button_row -%}
<div class="form-group">
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_widget(form) -}}
</div>
{%- endblock button_row %}
@ -146,14 +146,14 @@
{%- endblock datetime_row %}
{% block checkbox_row -%}
<div class="form-group{% if not valid %} has-error{% endif %}">
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ (not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_widget(form) -}}
{{- form_errors(form) -}}
</div>
{%- endblock checkbox_row %}
{% block radio_row -%}
<div class="form-group{% if not valid %} has-error{% endif %}">
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ (not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_widget(form) -}}
{{- form_errors(form) -}}
</div>

View File

@ -28,7 +28,7 @@ col-sm-2
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div class="form-group row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
<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 %}>
{{- form_label(form) -}}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form, widget_attr) -}}
@ -43,7 +43,7 @@ col-sm-2
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<fieldset class="form-group">
<fieldset{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
<div class="row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
{{- form_label(form) -}}
<div class="{{ block('form_group_class') }}">
@ -55,7 +55,7 @@ col-sm-2
{%- endblock fieldset_form_row %}
{% block submit_row -%}
<div class="form-group row">{#--#}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group row')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
<div class="{{ block('form_label_class') }}"></div>{#--#}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
@ -64,7 +64,7 @@ col-sm-2
{%- endblock submit_row %}
{% block reset_row -%}
<div class="form-group row">{#--#}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group row')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
<div class="{{ block('form_label_class') }}"></div>{#--#}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
@ -77,7 +77,7 @@ col-sm-10
{%- endblock form_group_class %}
{% block checkbox_row -%}
<div class="form-group row">{#--#}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group row')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
<div class="{{ block('form_label_class') }}"></div>{#--#}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}

View File

@ -282,7 +282,7 @@
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<{{ element|default('div') }} class="form-group">
<{{ element|default('div') }}{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}

View File

@ -187,7 +187,7 @@
{# Rows #}
{% block button_row -%}
<div class="form-group">
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_widget(form) -}}
</div>
{%- endblock button_row %}

View File

@ -325,7 +325,7 @@
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div {% with {attr: row_attr|default({})} %}{{ block('attributes') }}{% endwith %}>
<div{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}
{{- form_errors(form) -}}
{{- form_widget(form, widget_attr) -}}
@ -334,7 +334,7 @@
{%- endblock form_row -%}
{%- block button_row -%}
<div {% with {attr: row_attr|default({})} %}{{ block('attributes') }}{% endwith %}>
<div{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
{{- form_widget(form) -}}
</div>
{%- endblock button_row -%}

View File

@ -5,7 +5,7 @@
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<tr>
<tr{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
<td>
{{- form_label(form) -}}
</td>
@ -18,7 +18,7 @@
{%- endblock form_row -%}
{%- block button_row -%}
<tr>
<tr{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
<td></td>
<td>
{{- form_widget(form) -}}
@ -27,7 +27,8 @@
{%- endblock button_row -%}
{%- block hidden_row -%}
<tr style="display: none">
{%- set style = row_attr.style is defined ? (row_attr.style ~ (row_attr.style|trim|last != ';' ? '; ')) : '' -%}
<tr{% with {attr: row_attr|merge({style: (style ~ ' display: none')|trim})} %}{{ block('attributes') }}{% endwith %}>
<td colspan="2">
{{- form_widget(form) -}}
</td>

View File

@ -277,7 +277,7 @@
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div class="row">
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' row')|trim})} %}{{ block('attributes') }}{% endwith %}>
<div class="large-12 columns{% if (not compound or force_error|default(false)) and not valid %} error{% endif %}">
{{- form_label(form) -}}
{{- form_widget(form, widget_attr) -}}
@ -308,7 +308,7 @@
{%- endblock datetime_row %}
{% block checkbox_row -%}
<div class="row">
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' row')|trim})} %}{{ block('attributes') }}{% endwith %}>
<div class="large-12 columns{% if not valid %} error{% endif %}">
{{ form_widget(form) }}
{{ form_errors(form) }}
@ -317,7 +317,7 @@
{%- endblock checkbox_row %}
{% block radio_row -%}
<div class="row">
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' row')|trim})} %}{{ block('attributes') }}{% endwith %}>
<div class="large-12 columns{% if not valid %} error{% endif %}">
{{ form_widget(form) }}
{{ form_errors(form) }}

View File

@ -26,7 +26,7 @@
"symfony/asset": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/finder": "~3.4|~4.0",
"symfony/form": "^4.3.4",
"symfony/form": "^4.3.5",
"symfony/http-foundation": "~4.3",
"symfony/http-kernel": "~3.4|~4.0",
"symfony/mime": "~4.3",
@ -48,7 +48,7 @@
},
"conflict": {
"symfony/console": "<3.4",
"symfony/form": "<4.3.4",
"symfony/form": "<4.3.5",
"symfony/http-foundation": "<4.3",
"symfony/translation": "<4.2",
"symfony/workflow": "<4.3"

View File

@ -38,7 +38,7 @@
"symfony/css-selector": "~3.4|~4.0",
"symfony/dom-crawler": "^4.3",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/form": "^4.3.4",
"symfony/form": "^4.3.5",
"symfony/expression-language": "~3.4|~4.0",
"symfony/http-client": "^4.3",
"symfony/mailer": "^4.3",
@ -72,7 +72,7 @@
"symfony/console": "<4.3",
"symfony/dotenv": "<4.2",
"symfony/dom-crawler": "<4.3",
"symfony/form": "<4.3",
"symfony/form": "<4.3.5",
"symfony/messenger": "<4.3.6",
"symfony/property-info": "<3.4",
"symfony/serializer": "<4.2",