Skip to content

Commit

Permalink
feature #30320 [Form][TwigBridge] Add row_attr to form theme (alexand…
Browse files Browse the repository at this point in the history
…er-schranz)

This PR was squashed before being merged into the 4.3-dev branch (closes #30320).

Discussion
----------

[Form][TwigBridge] Add row_attr to form theme

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | waiting for confirmation to implement
| Fixed tickets |
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Currently you need to copy the whole form_row block if you just want to add a class to the form_row div. Instead we could introduce a `row_attr` which can then simple be set the following in the theme e.g.:

```twig
{% block form_row %}
    {% set row_attr = { class: 'form__field' } %}
    {{ parent() }}
{% endblock %}
```

or in php:

```
$builder->add('test', TextType::class, ['row_attr' => ['class' => 'form__field']]);
```

Commits
-------

7ab1b00 [Form][TwigBridge] Add row_attr to form theme
  • Loading branch information
fabpot committed Mar 31, 2019
2 parents ce24e15 + 7ab1b00 commit 6bc2ae4
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div>
<div {% with {attr: row_attr|default({})} %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}
{{- form_errors(form) -}}
{{- form_widget(form, widget_attr) -}}
Expand All @@ -334,7 +334,7 @@
{%- endblock form_row -%}

{%- block button_row -%}
<div>
<div {% with {attr: row_attr|default({})} %}{{ block('attributes') }}{% endwith %}>
{{- form_widget(form) -}}
</div>
{%- endblock button_row -%}
Expand Down

0 comments on commit 6bc2ae4

Please sign in to comment.