8000 feature #34880 [Twig][Form] Twig theme for Foundation 6 (Lyssal) · symfony/symfony@c146de1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c146de1

Browse files
committed
feature #34880 [Twig][Form] Twig theme for Foundation 6 (Lyssal)
This PR was squashed before being merged into the 5.1-dev branch (closes #34880). Discussion ---------- [Twig][Form] Twig theme for Foundation 6 | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | - Hi, I propose a form theme for Foundation 6. This layout stylizes buttons, percent / money widgets and permits switch inputs adding a 'switch-input' attribute (as for https://symfony.com/blog/new-in-symfony-4-4-bootstrap-custom-switches). ![Foundation_6](https://user-images.githubusercontent.com/10855303/70390292-184cdc80-19ca-11ea-8ad8-090358dd9e35.png) ```php public function buildForm(FormBuilderInterface $builder, array $options): void { $builder // ... ->add('checkbox-switch', Type\CheckboxType::class, [ 'attr' => [ 'class' => 'switch-input', ], ]) ; } ``` Commits ------- e47a134 [Twig][Form] Twig theme for Foundation 6
2 parents cc64b02 + e47a134 commit c146de1

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ CHANGELOG
88
* removed `transChoice` filter and token
99
* `HttpFoundationExtension` requires a `UrlHelper` on instantiation
1010
* removed support for implicit STDIN usage in the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit.
11+
* added form theme for Foundation 6
12+
* added support for Foundation 6 switches: add the `switch-input` class to the attributes of a `CheckboxType`
1113

1214
4.4.0
1315
-----
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{% extends "form_div_layout.html.twig" %}
2+
3+
{%- block checkbox_row -%}
4+
{%- set parent_class = parent_class|default(attr.class|default('')) -%}
5+
{%- if 'switch-input' in parent_class -%}
6+
{{- form_label(form) -}}
7+
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' switch-input')|trim}) -%}
8+
{{- form_widget(form) -}}
9+
<label class="switch-paddle" for="{{ form.vars.id }}"></label>
10+
{{- form_errors(form) -}}
11+
{%- else -%}
12+
{{- block('form_row') -}}
13+
{%- endif -%}
14+
{%- endblock checkbox_row -%}
15+
16+
{% block money_widget -%}
17+
{% set prepend = not (money_pattern starts with '{{') %}
18+
{% set append = not (money_pattern ends with '}}') %}
19+
{% if prepend or append %}
20+
<div class="input-group">
21+
{% if prepend %}
22+
<span class="input-group-label">{{ money_pattern|form_encode_currency }}</span>
23+
{% endif %}
24+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' input-group-field')|trim}) %}
25+
{{- block('form_widget_simple') -}}
26+
{% if append %}
27+
<span class="input-group-label">{{ money_pattern|form_encode_currency }}</span>
28+
{% endif %}
29+
</div>
30+
{% else %}
31+
{{- block('form_widget_simple') -}}
32+
{% endif %}
33+
{%- endblock money_widget %}
34+
35+
{% block percent_widget -%}
36+
{%- if symbol -%}
37+
<div class="input-group">
38+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' input-group-field')|trim}) %}
39+
{{- block('form_widget_simple') -}}
40+
<span class="input-group-label">{{ symbol|default('%') }}</span>
41+
</div>
42+
{%- else -%}
43+
{{- block('form_widget_simple') -}}
44+
{%- endif -%}
45+
{%- endblock percent_widget %}
46+
47+
{% block button_widget -%}
48+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' button')|trim}) %}
49+
{{- parent() -}}
50+
{%- endblock button_widget %}

0 commit comments

Comments
 (0)
0