[Form] Adding an exception for an invalid widget option in DateType
This commit is contained in:
parent
81deedfc1b
commit
78b2062c5e
@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
|||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\Form\FormBuilder;
|
use Symfony\Component\Form\FormBuilder;
|
||||||
|
use Symfony\Component\Form\Exception\FormException;
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\PaddedChoiceList;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\PaddedChoiceList;
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\MonthChoiceList;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\MonthChoiceList;
|
||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
@ -36,7 +37,7 @@ class DateType extends AbstractType
|
|||||||
|
|
||||||
if ($options['widget'] === 'text') {
|
if ($options['widget'] === 'text') {
|
||||||
$builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $options['format'], \IntlDateFormatter::NONE));
|
$builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $options['format'], \IntlDateFormatter::NONE));
|
||||||
} else {
|
} elseif ($options['widget'] == 'choice') {
|
||||||
// Only pass a subset of the options to children
|
// Only pass a subset of the options to children
|
||||||
$yearOptions = array(
|
$yearOptions = array(
|
||||||
'choice_list' => new PaddedChoiceList(
|
'choice_list' => new PaddedChoiceList(
|
||||||
@ -58,6 +59,8 @@ class DateType extends AbstractType
|
|||||||
->add('month', 'choice', $monthOptions)
|
->add('month', 'choice', $monthOptions)
|
||||||
->add('day', 'choice', $dayOptions)
|
->add('day', 'choice', $dayOptions)
|
||||||
->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
|
->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
|
||||||
|
} else {
|
||||||
|
throw new FormException('The "widget" option must be set to either "text" or "choice".');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['input'] === 'string') {
|
if ($options['input'] === 'string') {
|
||||||
|
@ -25,6 +25,16 @@ class DateTypeTest extends LocalizedTestCase
|
|||||||
\Locale::setDefault('de_AT');
|
\Locale::setDefault('de_AT');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Symfony\Component\Form\Exception\FormException
|
||||||
|
*/
|
||||||
|
public function testInvalidWidgetOption()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('date', 'name', array(
|
||||||
|
'widget' => 'fake_widget',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public function testSubmitFromInputDateTime()
|
public function testSubmitFromInputDateTime()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('date', null, array(
|
$form = $this->factory->create('date', null, array(
|
||||||
|
Reference in New Issue
Block a user