[Form] Implemented getAllowedOptionValues() for core types

This commit is contained in:
Bernhard Schussek 2011-05-13 18:58:19 +02:00
parent 486a01bfe2
commit 7570e04589
7 changed files with 120 additions and 9 deletions

View File

@ -55,9 +55,6 @@ class DateTimeType extends AbstractType
if (isset($options['time_widget'])) {
$timeOptions['widget'] = $options['time_widget'];
}
if (isset($options['time_format'])) {
$timeOptions['format'] = $options['time_format'];
}
$timeOptions['input'] = 'array';
@ -109,7 +106,6 @@ class DateTimeType extends AbstractType
'date_format' => null,
'time_pattern' => null,
'time_widget' => null,
'time_format' => null,
/* Defaults for date field */
'years' => range(date('Y') - 5, date('Y') + 5),
'months' => range(1, 12),
@ -122,6 +118,35 @@ class DateTimeType extends AbstractType
);
}
public function getAllowedOptionValues(array $options)
{
return array(
'input' => array(
'datetime',
'string',
'timestamp',
'array',
),
'date_widget' => array(
null, // inherit default from DateType
'text',
'choice',
),
'date_format' => array(
null, // inherit default from DateType
\IntlDateFormatter::FULL,
\IntlDateFormatter::LONG,
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::SHORT,
),
'time_widget' => array(
null, // inherit default from TimeType
'text',
'choice',
),
);
}
public function getName()
{
return 'datetime';

View File

@ -37,7 +37,7 @@ class DateType extends AbstractType
if ($options['widget'] === 'text') {
$builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $options['format'], \IntlDateFormatter::NONE));
} elseif ($options['widget'] == 'choice') {
} else {
// Only pass a subset of the options to children
$yearOptions = array(
'choice_list' => new PaddedChoiceList(
@ -59,8 +59,6 @@ class DateType extends AbstractType
->add('month', 'choice', $monthOptions)
->add('day', 'choice', $dayOptions)
->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') {
@ -124,6 +122,28 @@ class DateType extends AbstractType
);
}
public function getAllowedOptionValues(array $options)
{
return array(
'input' => array(
'datetime',
'string',
'timestamp',
'array',
),
'widget' => array(
'text',
'choice',
),
'format' => array(
\IntlDateFormatter::FULL,
\IntlDateFormatter::LONG,
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::SHORT,
),
);
}
public function getParent(array $options)
{
return $options['widget'] === 'text' ? 'field' : 'form';

View File

@ -61,6 +61,16 @@ class FileType extends AbstractType
);
}
public function getAllowedOptionValues(array $options)
{
return array(
'type' => array(
'string',
'file',
),
);
}
public function getName()
{
return 'file';

View File

@ -29,7 +29,22 @@ class IntegerType extends AbstractType
'precision' => null,
'grouping' => false,
// Integer cast rounds towards 0, so do the same when displaying fractions
'rounding_mode' => IntegerToLocalizedStringTransformer::ROUND_DOWN,
'rounding_mode' => \NumberFormatter::ROUND_DOWN,
);
}
public function getAllowedOptionValues(array $options)
{
return array(
'rounding_mode' => array(
\NumberFormatter::ROUND_FLOOR,
\NumberFormatter::ROUND_DOWN,
\NumberFormatter::ROUND_HALFDOWN,
\NumberFormatter::ROUND_HALFEVEN,
\NumberFormatter::ROUND_HALFUP,
\NumberFormatter::ROUND_UP,
\NumberFormatter::ROUND_CEILING,
),
);
}

View File

@ -28,7 +28,22 @@ class NumberType extends AbstractType
// default precision is locale specific (usually around 3)
'precision' => null,
'grouping' => false,
'rounding_mode' => NumberToLocalizedStringTransformer::ROUND_HALFUP,
'rounding_mode' => \NumberFormatter::ROUND_HALFUP,
);
}
public function getAllowedOptionValues(array $options)
{
return array(
'rounding_mode' => array(
\NumberFormatter::ROUND_FLOOR,
\NumberFormatter::ROUND_DOWN,
\NumberFormatter::ROUND_HALFDOWN,
\NumberFormatter::ROUND_HALFEVEN,
\NumberFormatter::ROUND_HALFUP,
\NumberFormatter::ROUND_UP,
\NumberFormatter::ROUND_CEILING,
),
);
}

View File

@ -30,6 +30,16 @@ class PercentType extends AbstractType
);
}
public function getAllowedOptionValues(array $options)
{
return array(
'type' => array(
'fractional',
'integer',
),
);
}
public function getParent(array $options)
{
return 'field';

View File

@ -96,6 +96,22 @@ class TimeType extends AbstractType
);
}
public function getAllowedOptionValues(array $options)
{
return array(
'input' => array(
'datetime',
'string',
'timestamp',
'array',
),
'widget' => array(
'text',
'choice',
),
);
}
public function getName()
{
return 'time';