From 63761d96c1d36bfca8131e18c98d262ab26636f3 Mon Sep 17 00:00:00 2001 From: Luis Galeas Date: Mon, 12 Dec 2016 12:57:13 +0000 Subject: [PATCH 1/3] DateIntervalType: 'invert' should not inherit the 'required' option --- .../Form/Extension/Core/Type/DateIntervalType.php | 2 ++ .../Extension/Core/Type/DateIntervalTypeTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php index fb2b7d7ff3ec8..8dfcf57d686a2 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php @@ -134,6 +134,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add($childForm); } } + // Invert should not inherit the required option + $invertOptions['required'] = false; if ($options['with_invert']) { $builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', $invertOptions); } 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 e40c0949f6961..2adf3ba5429ae 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php @@ -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')); + } } From e60d78af74f0676ad80a0a9e5d65689f2217bfb1 Mon Sep 17 00:00:00 2001 From: Luis Galeas Date: Mon, 12 Dec 2016 17:50:40 +0000 Subject: [PATCH 2/3] DateIntervalType - refactor 'with_invert' options --- .../Form/Extension/Core/Type/DateIntervalType.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php index 8dfcf57d686a2..e4f46d8926502 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php @@ -107,9 +107,6 @@ 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) { @@ -117,10 +114,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) $childOptions[$part][$passOpt] = $options[$passOpt]; } } - if ($options['with_invert']) { - $invertOptions[$passOpt] = $options[$passOpt]; - } } + foreach ($this->timeParts as $part) { if ($options['with_'.$part]) { $childForm = $builder->create($part, self::$widgets[$options['widget']], $childOptions[$part]); @@ -134,10 +129,12 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add($childForm); } } - // Invert should not inherit the required option - $invertOptions['required'] = false; 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'], + )); } $builder->addViewTransformer(new DateIntervalToArrayTransformer($parts, 'text' === $options['widget'])); } From eb5afc008f4df64278fe3334cd60327f189535fc Mon Sep 17 00:00:00 2001 From: Luis Galeas Date: Mon, 12 Dec 2016 18:11:37 +0000 Subject: [PATCH 3/3] DateIntervalType --- remove extra space --- .../Component/Form/Extension/Core/Type/DateIntervalType.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php index e4f46d8926502..946d8a3159754 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php @@ -115,7 +115,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) } } } - foreach ($this->timeParts as $part) { if ($options['with_'.$part]) { $childForm = $builder->create($part, self::$widgets[$options['widget']], $childOptions[$part]);