Skip to content

Commit fa608a8

Browse files
committed
Merge branch '3.2'
* 3.2: [WebProfilerBundle] Fix AJAX panel with fetch requests Don’t compile when Opcache is not enabled on CLI DateIntervalType: 'invert' should not inherit the 'required' option [Form] DateIntervalType: Do not try to translate choices [TwigBridge] fix constructor args check Allow simple-phpunit to be used with an HTTP proxy Minor fixes for 3.2 Fix a web profiler form issue with fields added to the form after the form was built do not trigger deprecations for valid YAML Write an exception message in a one heading line [Workflow] Added missing docblock [Finder] Refine phpdoc about argument for NumberComparator Fixed max width from ajax request url element (td) Fix unresolved parameters from default bundle configs in debug:config [github] Tweak PR template [Serializer] Optimize max depth checking
2 parents 40ac080 + 103f62d commit fa608a8

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

Extension/Core/Type/DateIntervalType.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,19 @@ public function buildForm(FormBuilderInterface $builder, array $options)
102102
$childOptions[$part] = array();
103103
$childOptions[$part]['error_bubbling'] = true;
104104
if ('choice' === $options['widget']) {
105+
$childOptions[$part]['choice_translation_domain'] = false;
105106
$childOptions[$part]['choices'] = $options[$part];
106107
$childOptions[$part]['placeholder'] = $options['placeholder'][$part];
107108
}
108109
}
109110
}
110-
$invertOptions = array(
111-
'error_bubbling' => true,
112-
);
113111
// Append generic carry-along options
114112
foreach (array('required', 'translation_domain') as $passOpt) {
115113
foreach ($this->timeParts as $part) {
116114
if ($options['with_'.$part]) {
117115
$childOptions[$part][$passOpt] = $options[$passOpt];
118116
}
119117
}
120-
if ($options['with_invert']) {
121-
$invertOptions[$passOpt] = $options[$passOpt];
122-
}
123118
}
124119
foreach ($this->timeParts as $part) {
125120
if ($options['with_'.$part]) {
@@ -135,7 +130,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
135130
}
136131
}
137132
if ($options['with_invert']) {
138-
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', $invertOptions);
133+
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', array(
134+
'error_bubbling' => true,
135+
'required' => false,
136+
'translation_domain' => $options['translation_domain'],
137+
));
139138
}
140139
$builder->addViewTransformer(new DateIntervalToArrayTransformer($parts, 'text' === $options['widget']));
141140
}

Tests/Extension/Core/Type/DateIntervalTypeTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

14+
use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
1415
use Symfony\Component\Form\FormError;
1516
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
1617

@@ -364,4 +365,38 @@ public function testDateTypeChoiceErrorsBubbleUp()
364365
$this->assertSame(array(), iterator_to_array($form['years']->getErrors()));
365366
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
366367
}
368+
369+
public function testTranslationsAreDisabledForChoiceWidget()
370+
{
371+
$form = $this->factory->create(
372+
DateIntervalType::class,
373+
null,
374+
array(
375+
'widget' => 'choice',
376+
'with_hours' => true,
377+
'with_minutes' => true,
378+
'with_seconds' => true,
379+
)
380+
);
381+
$this->assertFalse($form->get('years')->getConfig()->getOption('choice_translation_domain'));
382+
$this->assertFalse($form->get('months')->getConfig()->getOption('choice_translation_domain'));
383+
$this->assertFalse($form->get('days')->getConfig()->getOption('choice_translation_domain'));
384+
$this->assertFalse($form->get('hours')->getConfig()->getOption('choice_translation_domain'));
385+
$this->assertFalse($form->get('minutes')->getConfig()->getOption('choice_translation_domain'));
386+
$this->assertFalse($form->get('seconds')->getConfig()->getOption('choice_translation_domain'));
387+
}
388+
389+
public function testInvertDoesNotInheritRequiredOption()
390+
{
391+
$form = $this->factory->create(
392+
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
393+
null,
394+
array(
395+
'input' => 'dateinterval',
396+
'with_invert' => true,
397+
'required' => true,
398+
)
399+
);
400+
$this->assertFalse($form->get('invert')->getConfig()->getOption('required'));
401+
}
367402
}

0 commit comments

Comments
 (0)