Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DateIntervalType: 'invert' should not inherit the 'required' option #20877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}
}
}
$invertOptions = array(
'error_bubbling' => true,
);
// Append generic carry-along options
foreach (array('required', 'translation_domain') as $passOpt) {
foreach ($this->timeParts as $part) {
if ($options['with_'.$part]) {
$childOptions[$part][$passOpt] = $options[$passOpt];
}
}
if ($options['with_invert']) {
$invertOptions[$passOpt] = $options[$passOpt];
}
}
foreach ($this->timeParts as $part) {
if ($options['with_'.$part]) {
Expand All @@ -135,7 +129,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}
}
if ($options['with_invert']) {
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', $invertOptions);
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', array(
'error_bubbling' => true,
'required' => false,
'translation_domain' => $options['translation_domain'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the translation_domain option needed here at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the previous behavior, not an addition. Removing that should be a separate issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway it should be kept IMHO. It's used to translate the Invert label, so it makes sense to use the same translation domain as for the whole widget.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ogizanagi Indeed, you are right.

));
}
$builder->addViewTransformer(new DateIntervalToArrayTransformer($parts, 'text' === $options['widget']));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,18 @@ public function testDateTypeChoiceErrorsBubbleUp()
$this->assertSame(array(), iterator_to_array($form['years']->getErrors()));
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
}

public function testInvertDoesNotInheritRequiredOption()
{
$form = $this->factory->create(
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
null,
array(
'input' => 'dateinterval',
'with_invert' => true,
'required' => true,
)
);
$this->assertFalse($form->get('invert')->getConfig()->getOption('required'));
}
}