Skip to content

Commit 99f59e2

Browse files
author
Romaric Drigon
committed
Supporting Bootstrap 4 custom switches
1 parent 6253369 commit 99f59e2

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* the `LintCommand` lints all the templates stored in all configured Twig paths if none argument is provided
1111
* deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit.
1212
* added `--show-deprecations` option to the `lint:twig` command
13+
* added support for Bootstrap4 switches, use `switch-custom` as `label_attr` in a `CheckboxType`
1314

1415
4.3.0
1516
-----

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@
166166
<div class="custom-control custom-checkbox{{ 'checkbox-inline' in parent_label_class ? ' custom-control-inline' }}">
167167
{{- form_label(form, null, { widget: parent() }) -}}
168168
</div>
169+
{%- elseif 'switch-custom' in parent_label_class -%}
170+
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
171+
<div class="custom-control custom-switch{{ 'switch-inline' in parent_label_class ? ' custom-control-inline' }}">
172+
{{- form_label(form, null, { widget: parent() }) -}}
173+
</div>
169174
{%- else -%}
170175
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
171176
<div class="form-check{{ 'checkbox-inline' in parent_label_class ? ' form-check-inline' }}">
@@ -238,7 +243,7 @@
238243
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
239244
{%- if widget is defined -%}
240245
{% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) %}
241-
{% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class) %}
246+
{% 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) %}
242247
{%- if is_parent_custom or is_custom -%}
243248
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%}
244249
{%- else %}

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
@@ -172,7 +172,7 @@
172172

173173
{% block choice_label -%}
174174
{# remove the checkbox-inline and radio-inline class, it's only useful for embed labels #}
175-
{%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%}
175+
{%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': '', 'switch-custom': ''})|trim}) -%}
176176
{{- block('form_label') -}}
177177
{% endblock choice_label %}
178178

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy