From 99f59e262f4f68c673d81df216e6022f31eae55e Mon Sep 17 00:00:00 2001 From: Romaric Drigon Date: Fri, 11 Oct 2019 14:19:34 +0200 Subject: [PATCH] Supporting Bootstrap 4 custom switches --- src/Symfony/Bridge/Twig/CHANGELOG.md | 1 + .../Twig/Resources/views/Form/bootstrap_4_layout.html.twig | 7 ++++++- .../Resources/views/Form/bootstrap_base_layout.html.twig | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index a86faea00b..0db211232e 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG * the `LintCommand` lints all the templates stored in all configured Twig paths if none argument is provided * deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit. * added `--show-deprecations` option to the `lint:twig` command + * added support for Bootstrap4 switches, use `switch-custom` as `label_attr` in a `CheckboxType` 4.3.0 ----- 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 ef45624c4e..117ddedf6b 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 @@ -166,6 +166,11 @@
{{- form_label(form, null, { widget: parent() }) -}}
+ {%- elseif 'switch-custom' in parent_label_class -%} + {%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%} +
+ {{- form_label(form, null, { widget: parent() }) -}} +
{%- else -%} {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
@@ -238,7 +243,7 @@ {#- Do not display the label if widget is not defined in order to prevent double label rendering -#} {%- if widget is defined -%} {% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) %} - {% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class) %} + {% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class or 'switch-custom' in label_attr.class) %} {%- if is_parent_custom or is_custom -%} {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%} {%- else %} diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig index a6ee019a09..f74bd57002 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig @@ -172,7 +172,7 @@ {% block choice_label -%} {# remove the checkbox-inline and radio-inline class, it's only useful for embed labels #} - {%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%} + {%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': '', 'switch-custom': ''})|trim}) -%} {{- block('form_label') -}} {% endblock choice_label %}