Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 25ff59b

Browse filesBrowse files
committed
[Form] Limit allowed types for 'empty_value' TimeType option
1 parent 4002e6f commit 25ff59b
Copy full SHA for 25ff59b

File tree

2 files changed

+34
-17
lines changed
Filter options

2 files changed

+34
-17
lines changed

‎src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
+24-17Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
2222
use Symfony\Component\Form\FormView;
2323
use Symfony\Component\OptionsResolver\Options;
24-
use Symfony\Component\OptionsResolver\OptionsResolver;
24+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
2525

2626
class TimeType extends AbstractType
2727
{
@@ -157,7 +157,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
157157
/**
158158
* {@inheritdoc}
159159
*/
160-
public function configureOptions(OptionsResolver $resolver)
160+
public function setDefaultOptions(OptionsResolverInterface $resolver)
161161
{
162162
$compound = function (Options $options) {
163163
return $options['widget'] !== 'single_text';
@@ -214,24 +214,31 @@ public function configureOptions(OptionsResolver $resolver)
214214
'compound' => $compound,
215215
));
216216

217-
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
218-
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
219-
220-
$resolver->setAllowedValues('input', array(
221-
'datetime',
222-
'string',
223-
'timestamp',
224-
'array',
217+
$resolver->setNormalizers(array(
218+
'empty_value' => $placeholderNormalizer,
219+
'placeholder' => $placeholderNormalizer,
225220
));
226-
$resolver->setAllowedValues('widget', array(
227-
'single_text',
228-
'text',
229-
'choice',
221+
222+
$resolver->setAllowedValues(array(
223+
'input' => array(
224+
'datetime',
225+
'string',
226+
'timestamp',
227+
'array',
228+
),
229+
'widget' => array(
230+
'single_text',
231+
'text',
232+
'choice',
233+
),
230234
));
231235

232-
$resolver->setAllowedTypes('hours', 'array');
233-
$resolver->setAllowedTypes('minutes', 'array');
234-
$resolver->setAllowedTypes('seconds', 'array');
236+
$resolver->setAllowedTypes(array(
237+
'hours' => 'array',
238+
'minutes' => 'array',
239+
'seconds' => 'array',
240+
'empty_value' => array('string', 'boolean', 'null'),
241+
));
235242
}
236243

237244
/**

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,14 @@ public function testThrowExceptionIfSecondsIsInvalid()
731731
'seconds' => 'bad value',
732732
));
733733
}
734+
735+
/**
736+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
737+
*/
738+
public function testThrowExceptionIfEmptyValueIsInvalid()
739+
{
740+
$this->factory->create('time', null, array(
741+
'empty_value' => array(),
742+
));
743+
}
734744
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.