diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig
index 5fb3a18f1d532..f2fe8bf3d2588 100644
--- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig
+++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig
@@ -94,13 +94,32 @@
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
{{- form_errors(form) -}}
- {%- if with_years %}{{ form_widget(form.years) }}{% endif -%}
- {%- if with_months %}{{ form_widget(form.months) }}{% endif -%}
- {%- if with_weeks %}{{ form_widget(form.weeks) }}{% endif -%}
- {%- if with_days %}{{ form_widget(form.days) }}{% endif -%}
- {%- if with_hours %}{{ form_widget(form.hours) }}{% endif -%}
- {%- if with_minutes %}{{ form_widget(form.minutes) }}{% endif -%}
- {%- if with_seconds %}{{ form_widget(form.seconds) }}{% endif -%}
+
+
+
+
+ {%- if with_years %}{{ form_label(form.years) }} | {% endif -%}
+ {%- if with_months %}{{ form_label(form.months) }} | {% endif -%}
+ {%- if with_weeks %}{{ form_label(form.weeks) }} | {% endif -%}
+ {%- if with_days %}{{ form_label(form.days) }} | {% endif -%}
+ {%- if with_hours %}{{ form_label(form.hours) }} | {% endif -%}
+ {%- if with_minutes %}{{ form_label(form.minutes) }} | {% endif -%}
+ {%- if with_seconds %}{{ form_label(form.seconds) }} | {% endif -%}
+
+
+
+
+ {%- if with_years %}{{ form_widget(form.years) }} | {% endif -%}
+ {%- if with_months %}{{ form_widget(form.months) }} | {% endif -%}
+ {%- if with_weeks %}{{ form_widget(form.weeks) }} | {% endif -%}
+ {%- if with_days %}{{ form_widget(form.days) }} | {% endif -%}
+ {%- if with_hours %}{{ form_widget(form.hours) }} | {% endif -%}
+ {%- if with_minutes %}{{ form_widget(form.minutes) }} | {% endif -%}
+ {%- if with_seconds %}{{ form_widget(form.seconds) }} | {% endif -%}
+
+
+
+
{%- if with_invert %}{{ form_widget(form.invert) }}{% endif -%}
{%- endif -%}
diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
index e1d09153dfe60..1695e5dbc4a15 100644
--- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
+++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
@@ -136,13 +136,30 @@
{%- else -%}
{{- form_errors(form) -}}
- {%- if with_years %}{{ form_widget(form.years) }}{% endif -%}
- {%- if with_months %}{{ form_widget(form.months) }}{% endif -%}
- {%- if with_weeks %}{{ form_widget(form.weeks) }}{% endif -%}
- {%- if with_days %}{{ form_widget(form.days) }}{% endif -%}
- {%- if with_hours %}{{ form_widget(form.hours) }}{% endif -%}
- {%- if with_minutes %}{{ form_widget(form.minutes) }}{% endif -%}
- {%- if with_seconds %}{{ form_widget(form.seconds) }}{% endif -%}
+
+
+
+ {%- if with_years %}{{ form_label(form.years) }} | {% endif -%}
+ {%- if with_months %}{{ form_label(form.months) }} | {% endif -%}
+ {%- if with_weeks %}{{ form_label(form.weeks) }} | {% endif -%}
+ {%- if with_days %}{{ form_label(form.days) }} | {% endif -%}
+ {%- if with_hours %}{{ form_label(form.hours) }} | {% endif -%}
+ {%- if with_minutes %}{{ form_label(form.minutes) }} | {% endif -%}
+ {%- if with_seconds %}{{ form_label(form.seconds) }} | {% endif -%}
+
+
+
+
+ {%- if with_years %}{{ form_widget(form.years) }} | {% endif -%}
+ {%- if with_months %}{{ form_widget(form.months) }} | {% endif -%}
+ {%- if with_weeks %}{{ form_widget(form.weeks) }} | {% endif -%}
+ {%- if with_days %}{{ form_widget(form.days) }} | {% endif -%}
+ {%- if with_hours %}{{ form_widget(form.hours) }} | {% endif -%}
+ {%- if with_minutes %}{{ form_widget(form.minutes) }} | {% endif -%}
+ {%- if with_seconds %}{{ form_widget(form.seconds) }} | {% endif -%}
+
+
+
{%- if with_invert %}{{ form_widget(form.invert) }}{% endif -%}
{%- endif -%}
diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php
index 6e8139f502dda..a3e48e83d6de1 100644
--- a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php
+++ b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php
@@ -99,8 +99,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$childOptions = array();
foreach ($this->timeParts as $part) {
if ($options['with_'.$part]) {
- $childOptions[$part] = array();
- $childOptions[$part]['error_bubbling'] = true;
+ $childOptions[$part] = array(
+ 'error_bubbling' => true,
+ 'label' => $options['labels'][$part],
+ );
if ('choice' === $options['widget']) {
$childOptions[$part]['choice_translation_domain'] = false;
$childOptions[$part]['choices'] = $options[$part];
@@ -131,6 +133,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}
if ($options['with_invert']) {
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', array(
+ 'label' => $options['labels']['invert'],
'error_bubbling' => true,
'required' => false,
'translation_domain' => $options['translation_domain'],
@@ -192,6 +195,21 @@ public function configureOptions(OptionsResolver $resolver)
return array_fill_keys($timeParts, $placeholder);
};
+ $labelsNormalizer = function (Options $options, array $labels) {
+ return array_replace(array(
+ 'years' => null,
+ 'months' => null,
+ 'days' => null,
+ 'weeks' => null,
+ 'hours' => null,
+ 'minutes' => null,
+ 'seconds' => null,
+ 'invert' => 'Negative interval',
+ ), array_filter($labels, function ($label) {
+ return null !== $label;
+ }));
+ };
+
$resolver->setDefaults(
array(
'with_years' => true,
@@ -220,9 +238,11 @@ public function configureOptions(OptionsResolver $resolver)
// this option.
'data_class' => null,
'compound' => $compound,
+ 'labels' => array(),
)
);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
+ $resolver->setNormalizer('labels', $labelsNormalizer);
$resolver->setAllowedValues(
'input',
@@ -260,6 +280,7 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setAllowedTypes('with_minutes', 'bool');
$resolver->setAllowedTypes('with_seconds', 'bool');
$resolver->setAllowedTypes('with_invert', 'bool');
+ $resolver->setAllowedTypes('labels', 'array');
}
/**
diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php
index 8d44e3c934a1f..34add119bea88 100644
--- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php
+++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php
@@ -399,4 +399,53 @@ public function testInvertDoesNotInheritRequiredOption()
);
$this->assertFalse($form->get('invert')->getConfig()->getOption('required'));
}
+
+ public function testCanChangeTimeFieldsLabels()
+ {
+ $form = $this->factory->create(
+ DateIntervalType::class,
+ null,
+ array(
+ 'required' => true,
+ 'with_invert' => true,
+ 'with_hours' => true,
+ 'with_minutes' => true,
+ 'with_seconds' => true,
+ 'labels' => array(
+ 'invert' => 'form.trans.invert',
+ 'years' => 'form.trans.years',
+ 'months' => 'form.trans.months',
+ 'days' => 'form.trans.days',
+ 'hours' => 'form.trans.hours',
+ 'minutes' => 'form.trans.minutes',
+ 'seconds' => 'form.trans.seconds',
+ ),
+ )
+ );
+
+ $view = $form->createView();
+ $this->assertSame('form.trans.invert', $view['invert']->vars['label']);
+ $this->assertSame('form.trans.years', $view['years']->vars['label']);
+ $this->assertSame('form.trans.months', $view['months']->vars['label']);
+ $this->assertSame('form.trans.days', $view['days']->vars['label']);
+ $this->assertSame('form.trans.hours', $view['hours']->vars['label']);
+ $this->assertSame('form.trans.minutes', $view['minutes']->vars['label']);
+ $this->assertSame('form.trans.seconds', $view['seconds']->vars['label']);
+ }
+
+ public function testInvertDefaultLabel()
+ {
+ $form = $this->factory->create(DateIntervalType::class, null, array('with_invert' => true));
+
+ $view = $form->createView();
+ $this->assertSame('Negative interval', $view['invert']->vars['label']);
+
+ $form = $this->factory->create(DateIntervalType::class, null, array(
+ 'with_invert' => true,
+ 'labels' => array('invert' => null),
+ ));
+
+ $view = $form->createView();
+ $this->assertSame('Negative interval', $view['invert']->vars['label']);
+ }
}