bug #28469 [Form][TwigBridge] fix not displaying labels when value is false (xabbuh)

This PR was merged into the 4.1 branch.

Discussion
----------

[Form][TwigBridge] fix not displaying labels when value is false

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28198
| License       | MIT
| Doc PR        |

Commits
-------

c4a6c9fa00 fix not displaying labels when value is false
This commit is contained in:
Nicolas Grekas 2018-09-18 14:47:11 +02:00
commit 1f98703e14
2 changed files with 10 additions and 3 deletions

View File

@ -64,11 +64,13 @@
{%- if datetime is not defined or not datetime -%}
<div {{ block('widget_container_attributes') -}}>
{%- endif %}
{%- if label is not same as(false) -%}
<div class="sr-only">
{{ form_label(form.year) }}
{{ form_label(form.month) }}
{{ form_label(form.day) }}
</div>
{%- endif -%}
{{- date_pattern|replace({
'{{ year }}': form_widget(form.year),
@ -89,10 +91,10 @@
{%- if datetime is not defined or false == datetime -%}
<div {{ block('widget_container_attributes') -}}>
{%- endif -%}
<div class="sr-only">{{ form_label(form.hour) }}</div>
{%- if label is not same as(false) -%}<div class="sr-only">{{ form_label(form.hour) }}</div>{%- endif -%}
{{- form_widget(form.hour) -}}
{%- if with_minutes -%}:<div class="sr-only">{{ form_label(form.minute) }}</div>{{ form_widget(form.minute) }}{%- endif -%}
{%- if with_seconds -%}:<div class="sr-only">{{ form_label(form.second) }}</div>{{ form_widget(form.second) }}{%- endif -%}
{%- if with_minutes -%}:{%- if label is not same as(false) -%}<div class="sr-only">{{ form_label(form.minute) }}</div>{%- endif -%}{{ form_widget(form.minute) }}{%- endif -%}
{%- if with_seconds -%}:{%- if label is not same as(false) -%}<div class="sr-only">{{ form_label(form.second) }}</div>{%- endif -%}{{ form_widget(form.second) }}{%- endif -%}
{%- if datetime is not defined or false == datetime -%}
</div>
{%- endif -%}

View File

@ -120,6 +120,11 @@ class DateTimeType extends AbstractType
'invalid_message_parameters',
)));
if (false === $options['label']) {
$dateOptions['label'] = false;
$timeOptions['label'] = false;
}
if (null !== $options['date_widget']) {
$dateOptions['widget'] = $options['date_widget'];
}