8000 bug #20877 DateIntervalType: 'invert' should not inherit the 'require… · symfony/symfony@0daa64f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0daa64f

Browse files
committed
bug #20877 DateIntervalType: 'invert' should not inherit the 'required' option (galeaspablo)
This PR was squashed before being merged into the 3.2 branch (closes #20877). Discussion ---------- DateIntervalType: 'invert' should not inherit the 'required' option | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20876 | License | MIT | Doc PR | - As explained in #20876, > In the DateIntervalType, there is a field, called 'invert', that allows for negative intervals. This is outputted as a checkbox. Which is fine, but it shouldn't be required. Commits ------- b1597f1 DateIntervalType: 'invert' should not inherit the 'required' option
2 parents e1e9479 + b1597f1 commit 0daa64f
< 8000 div class="d-flex flex-column gap-2" id="diff_file_tree" tabindex="-1">

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
108108
}
109109
}
110110
}
111-
$invertOptions = array(
112-
'error_bubbling' => true,
113-
);
114111
// Append generic carry-along options
115112
foreach (array('required', 'translation_domain') as $passOpt) {
116113
foreach ($this->timeParts as $part) {
117114
if ($options['with_'.$part]) {
118115
$childOptions[$part][$passOpt] = $options[$passOpt];
119116
}
120117
}
121-
if ($options['with_invert']) {
122-
$invertOptions[$passOpt] = $options[$passOpt];
123-
}
124118
}
125119
foreach ($this->timeParts as $part) {
126120
if ($options['with_'.$part]) {
@@ -136,7 +130,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
136130
}
137131
}
138132
if ($options['with_invert']) {
139-
$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+
));
140138
}
141139
$builder->addViewTransformer(new DateIntervalToArrayTransformer($parts, 'text' === $options['widget']));
142140
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ public function testDateTypeChoiceErrorsBubbleUp()
365365
$this->assertSame(array(), iterator_to_array($form['years']->getErrors()));
366366
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
367367
}
368+
368369
public function testTranslationsAreDisabledForChoiceWidget()
369370
{
370371
$form = $this->factory->create(
@@ -384,4 +385,18 @@ public function testTranslationsAreDisabledForChoiceWidget()
384385
$this->assertFalse($form->get('minutes')->getConfig()->getOption('choice_translation_domain'));
385386
$this->assertFalse($form->get('seconds')->getConfig()->getOption('choice_translation_domain'));
386387
}
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+
}
387402
}

0 commit comments

Comments
 (0)
0