[Form] Changed getDefaultOptions() to setDefaultOptions(OptionsResolver $resolver) in FormTypeInterface
This commit is contained in:
parent
b4e8bcfc5a
commit
027259eba4
111
UPGRADE-2.1.md
111
UPGRADE-2.1.md
@ -313,42 +313,6 @@
|
||||
}
|
||||
```
|
||||
|
||||
* The methods `getDefaultOptions()` and `getAllowedOptionValues()` of form
|
||||
types no longer receive an option array.
|
||||
|
||||
You can specify options that depend on other options using closures instead.
|
||||
|
||||
Before:
|
||||
|
||||
```
|
||||
public function getDefaultOptions(array $options)
|
||||
{
|
||||
$defaultOptions = array();
|
||||
|
||||
if ($options['multiple']) {
|
||||
$defaultOptions['empty_data'] = array();
|
||||
}
|
||||
|
||||
return $defaultOptions;
|
||||
}
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```
|
||||
public function getDefaultOptions()
|
||||
{
|
||||
return array(
|
||||
'empty_data' => function (Options $options, $previousValue) {
|
||||
return $options['multiple'] ? array() : $previousValue;
|
||||
}
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
The second argument `$previousValue` does not have to be specified if not
|
||||
needed.
|
||||
|
||||
* The `add()`, `remove()`, `setParent()`, `bind()` and `setData()` methods in
|
||||
the Form class now throw an exception if the form is already bound.
|
||||
|
||||
@ -570,6 +534,81 @@
|
||||
));
|
||||
```
|
||||
|
||||
* The following methods of `FormTypeInterface` and `FormTypeExtensionInterface`
|
||||
are deprecated and will be removed in Symfony 2.3:
|
||||
|
||||
* `getDefaultOptions`
|
||||
* `getAllowedOptionValues`
|
||||
|
||||
You should use the newly added `setDefaultOptions` instead, which gives you
|
||||
access to the OptionsResolver instance and with that a lot more power.
|
||||
|
||||
Before:
|
||||
|
||||
```
|
||||
public function getDefaultOptions(array $options)
|
||||
{
|
||||
return array(
|
||||
'gender' => 'male',
|
||||
);
|
||||
}
|
||||
|
||||
public function getAllowedOptionValues(array $options)
|
||||
{
|
||||
return array(
|
||||
'gender' => array('male', 'female'),
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'gender' => 'male',
|
||||
));
|
||||
|
||||
$resolver->setAllowedValues(array(
|
||||
'gender' => array('male', 'female'),
|
||||
));
|
||||
}
|
||||
```
|
||||
|
||||
You can specify options that depend on other options using closures.
|
||||
|
||||
Before:
|
||||
|
||||
```
|
||||
public function getDefaultOptions(array $options)
|
||||
{
|
||||
$defaultOptions = array();
|
||||
|
||||
if ($options['multiple']) {
|
||||
$defaultOptions['empty_data'] = array();
|
||||
}
|
||||
|
||||
return $defaultOptions;
|
||||
}
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'empty_data' => function (Options $options, $value) {
|
||||
return $options['multiple'] ? array() : $value;
|
||||
}
|
||||
));
|
||||
}
|
||||
```
|
||||
|
||||
The second argument `$value` contains the current default value and
|
||||
does not have to be specified if not needed.
|
||||
|
||||
### Validator
|
||||
|
||||
* The methods `setMessage()`, `getMessageTemplate()` and
|
||||
|
@ -20,6 +20,7 @@ use Symfony\Bridge\Doctrine\Form\EventListener\MergeDoctrineCollectionListener;
|
||||
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
abstract class DoctrineType extends AbstractType
|
||||
{
|
||||
@ -43,7 +44,7 @@ abstract class DoctrineType extends AbstractType
|
||||
}
|
||||
}
|
||||
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$registry = $this->registry;
|
||||
$type = $this;
|
||||
@ -71,7 +72,7 @@ abstract class DoctrineType extends AbstractType
|
||||
);
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'em' => null,
|
||||
'class' => null,
|
||||
'property' => null,
|
||||
@ -80,7 +81,7 @@ abstract class DoctrineType extends AbstractType
|
||||
'choices' => null,
|
||||
'choice_list' => $choiceList,
|
||||
'group_by' => null,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Bridge\Propel1\Form\DataTransformer\CollectionToArrayTransformer;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* ModelType class.
|
||||
@ -31,7 +32,7 @@ class ModelType extends AbstractType
|
||||
}
|
||||
}
|
||||
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$choiceList = function (Options $options) {
|
||||
return new ModelChoiceList(
|
||||
@ -43,7 +44,7 @@ class ModelType extends AbstractType
|
||||
);
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'template' => 'choice',
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -54,7 +55,7 @@ class ModelType extends AbstractType
|
||||
'choice_list' => $choiceList,
|
||||
'group_by' => null,
|
||||
'by_reference' => false,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
public function getParent(array $options)
|
||||
|
@ -18,6 +18,7 @@ use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\Event\FilterDataEvent;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Form type for use with the Security component's form-based authentication
|
||||
@ -74,17 +75,17 @@ class UserLoginFormType extends AbstractType
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Symfony\Component\Form\AbstractType::getDefaultOptions()
|
||||
* @see Symfony\Component\Form\AbstractType::setDefaultOptions()
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
/* Note: the form's intention must correspond to that for the form login
|
||||
* listener in order for the CSRF token to validate successfully.
|
||||
*/
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'intention' => 'authenticate',
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,7 +12,11 @@
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class AbstractType implements FormTypeInterface
|
||||
{
|
||||
/**
|
||||
@ -53,13 +57,32 @@ abstract class AbstractType implements FormTypeInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults($this->getDefaultOptions());
|
||||
$resolver->addAllowedValues($this->getAllowedOptionValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default options for this type.
|
||||
*
|
||||
* @return array The default options
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
|
||||
* Use {@link setDefaultOptions()} instead.
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Returns the allowed option values for each option (if any).
|
||||
*
|
||||
* @return array The allowed option values
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
|
||||
* Use {@link setDefaultOptions()} instead.
|
||||
*/
|
||||
public function getAllowedOptionValues()
|
||||
{
|
||||
|
@ -11,6 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class AbstractTypeExtension implements FormTypeExtensionInterface
|
||||
{
|
||||
/**
|
||||
@ -37,13 +42,32 @@ abstract class AbstractTypeExtension implements FormTypeExtensionInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults($this->getDefaultOptions());
|
||||
$resolver->addAllowedValues($this->getAllowedOptionValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default options form the extended type.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
|
||||
* Use {@link setDefaultOptions()} instead.
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Returns the allowed option values for each option (if any).
|
||||
*
|
||||
* @return array The allowed option values
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
|
||||
* Use {@link setDefaultOptions()} instead.
|
||||
*/
|
||||
public function getAllowedOptionValues()
|
||||
{
|
||||
|
@ -52,8 +52,6 @@ CHANGELOG
|
||||
"single_text" unless "with_seconds" is set to true
|
||||
* checkboxes of in an expanded multiple-choice field don't include the choice
|
||||
in their name anymore. Their names terminate with "[]" now.
|
||||
* [BC BREAK] FormType::getDefaultOptions() and FormType::getAllowedOptionValues()
|
||||
don't receive an options array anymore.
|
||||
* deprecated FormValidatorInterface and substituted its implementations
|
||||
by event subscribers
|
||||
* simplified CSRF protection and removed the csrf type
|
||||
@ -88,3 +86,9 @@ CHANGELOG
|
||||
* removed superfluous methods from DataMapperInterface
|
||||
* `mapFormToData`
|
||||
* `mapDataToForm`
|
||||
* [BC BREAK] FormType::getDefaultOptions() and FormType::getAllowedOptionValues()
|
||||
don't receive an options array anymore.
|
||||
* added `setDefaultOptions` to FormTypeInterface and FormTypeExtensionInterface
|
||||
which accepts an OptionsResolver instance
|
||||
* deprecated the methods `getDefaultOptions` and `getAllowedOptionValues`
|
||||
in FormTypeInterface and FormTypeExtensionInterface
|
||||
|
@ -12,17 +12,18 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class BirthdayType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'years' => range(date('Y') - 120, date('Y')),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CheckboxType extends AbstractType
|
||||
{
|
||||
@ -44,17 +45,17 @@ class CheckboxType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$emptyData = function (FormInterface $form, $clientData) {
|
||||
return $clientData;
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'value' => '1',
|
||||
'empty_data' => $emptyData,
|
||||
'single_control' => true,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\ChoiceToBooleanArrayTr
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToValuesTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToBooleanArrayTransformer;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ChoiceType extends AbstractType
|
||||
{
|
||||
@ -143,7 +144,7 @@ class ChoiceType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$choiceList = function (Options $options) {
|
||||
return new SimpleChoiceList(
|
||||
@ -169,7 +170,7 @@ class ChoiceType extends AbstractType
|
||||
return !$options['expanded'];
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choice_list' => $choiceList,
|
||||
@ -179,7 +180,7 @@ class ChoiceType extends AbstractType
|
||||
'empty_value' => $emptyValue,
|
||||
'error_bubbling' => false,
|
||||
'single_control' => $singleControl,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CollectionType extends AbstractType
|
||||
{
|
||||
@ -74,16 +75,16 @@ class CollectionType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'allow_add' => false,
|
||||
'allow_delete' => false,
|
||||
'prototype' => true,
|
||||
'prototype_name' => '__name__',
|
||||
'type' => 'text',
|
||||
'options' => array(),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,17 +13,18 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Locale\Locale;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CountryType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => Locale::getDisplayCountries(\Locale::getDefault()),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransf
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DateTimeType extends AbstractType
|
||||
{
|
||||
@ -129,13 +130,13 @@ class DateTimeType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$singleControl = function (Options $options) {
|
||||
return $options['widget'] === 'single_text';
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'input' => 'datetime',
|
||||
'data_timezone' => null,
|
||||
'user_timezone' => null,
|
||||
@ -164,15 +165,9 @@ class DateTimeType extends AbstractType
|
||||
// this option.
|
||||
'data_class' => null,
|
||||
'single_control' => $singleControl,
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllowedOptionValues()
|
||||
{
|
||||
return array(
|
||||
$resolver->setAllowedValues(array(
|
||||
'input' => array(
|
||||
'datetime',
|
||||
'string',
|
||||
@ -198,7 +193,7 @@ class DateTimeType extends AbstractType
|
||||
'text',
|
||||
'choice',
|
||||
),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,9 +22,12 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransf
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
|
||||
use Symfony\Component\Form\ReversedTransformer;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DateType extends AbstractType
|
||||
{
|
||||
const DEFAULT_FORMAT = \IntlDateFormatter::MEDIUM;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -33,7 +36,7 @@ class DateType extends AbstractType
|
||||
$format = $options['format'];
|
||||
$pattern = null;
|
||||
|
||||
$allowedFormatOptionValues = array(
|
||||
$allowedFormats = array(
|
||||
\IntlDateFormatter::FULL,
|
||||
\IntlDateFormatter::LONG,
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
@ -41,11 +44,9 @@ class DateType extends AbstractType
|
||||
);
|
||||
|
||||
// If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
|
||||
if (!in_array($format, $allowedFormatOptionValues, true)) {
|
||||
if (!in_array($format, $allowedFormats, true)) {
|
||||
if (is_string($format)) {
|
||||
$defaultOptions = $this->getDefaultOptions();
|
||||
|
||||
$format = $defaultOptions['format'];
|
||||
$format = self::DEFAULT_FORMAT;
|
||||
$pattern = $options['format'];
|
||||
} else {
|
||||
throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
|
||||
@ -164,19 +165,19 @@ class DateType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$singleControl = function (Options $options) {
|
||||
return $options['widget'] === 'single_text';
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'years' => range(date('Y') - 5, date('Y') + 5),
|
||||
'months' => range(1, 12),
|
||||
'days' => range(1, 31),
|
||||
'widget' => 'choice',
|
||||
'input' => 'datetime',
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'format' => self::DEFAULT_FORMAT,
|
||||
'data_timezone' => null,
|
||||
'user_timezone' => null,
|
||||
'empty_value' => null,
|
||||
@ -189,16 +190,10 @@ class DateType extends AbstractType
|
||||
// representation is not \DateTime, but an array, we need to unset
|
||||
// this option.
|
||||
'data_class' => null,
|
||||
'single_control' => $singleControl,
|
||||
);
|
||||
}
|
||||
'single_control' => $singleControl,
|
||||
));
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllowedOptionValues()
|
||||
{
|
||||
return array(
|
||||
$resolver->setAllowedValues(array(
|
||||
'input' => array(
|
||||
'datetime',
|
||||
'string',
|
||||
@ -210,7 +205,7 @@ class DateType extends AbstractType
|
||||
'text',
|
||||
'choice',
|
||||
),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class FileType extends AbstractType
|
||||
{
|
||||
@ -41,11 +42,11 @@ class FileType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'single_control' => true,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,7 @@ use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\Form\Exception\FormException;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class FormType extends AbstractType
|
||||
{
|
||||
@ -147,7 +148,7 @@ class FormType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
// Derive "data_class" option from passed "data" object
|
||||
$dataClass = function (Options $options) {
|
||||
@ -192,7 +193,7 @@ class FormType extends AbstractType
|
||||
return false !== $options['property_path'];
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'data' => null,
|
||||
'data_class' => $dataClass,
|
||||
'empty_data' => $emptyData,
|
||||
@ -212,7 +213,7 @@ class FormType extends AbstractType
|
||||
'virtual' => false,
|
||||
'single_control' => false,
|
||||
'translation_domain' => 'messages',
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,21 +12,22 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class HiddenType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
// hidden fields cannot have a required attribute
|
||||
'required' => false,
|
||||
// Pass errors to the parent
|
||||
'error_bubbling' => true,
|
||||
'single_control' => true,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class IntegerType extends AbstractType
|
||||
{
|
||||
@ -33,24 +34,18 @@ class IntegerType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
// default precision is locale specific (usually around 3)
|
||||
'precision' => null,
|
||||
'grouping' => false,
|
||||
// Integer cast rounds towards 0, so do the same when displaying fractions
|
||||
'rounding_mode' => \NumberFormatter::ROUND_DOWN,
|
||||
'single_control' => true,
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllowedOptionValues()
|
||||
{
|
||||
return array(
|
||||
$resolver->setAllowedValues(array(
|
||||
'rounding_mode' => array(
|
||||
\NumberFormatter::ROUND_FLOOR,
|
||||
\NumberFormatter::ROUND_DOWN,
|
||||
@ -60,7 +55,7 @@ class IntegerType extends AbstractType
|
||||
\NumberFormatter::ROUND_UP,
|
||||
\NumberFormatter::ROUND_CEILING,
|
||||
),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,17 +13,18 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Locale\Locale;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class LanguageType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => Locale::getDisplayLanguages(\Locale::getDefault()),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,17 +13,18 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Locale\Locale;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class LocaleType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => Locale::getDisplayLocales(\Locale::getDefault()),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class MoneyType extends AbstractType
|
||||
{
|
||||
@ -48,15 +49,15 @@ class MoneyType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'precision' => 2,
|
||||
'grouping' => false,
|
||||
'divisor' => 1,
|
||||
'currency' => 'EUR',
|
||||
'single_control' => true,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class NumberType extends AbstractType
|
||||
{
|
||||
@ -32,23 +33,17 @@ class NumberType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
// default precision is locale specific (usually around 3)
|
||||
'precision' => null,
|
||||
'grouping' => false,
|
||||
'rounding_mode' => \NumberFormatter::ROUND_HALFUP,
|
||||
'single_control' => true,
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllowedOptionValues()
|
||||
{
|
||||
return array(
|
||||
$resolver->setAllowedValues(array(
|
||||
'rounding_mode' => array(
|
||||
\NumberFormatter::ROUND_FLOOR,
|
||||
\NumberFormatter::ROUND_DOWN,
|
||||
@ -58,7 +53,7 @@ class NumberType extends AbstractType
|
||||
\NumberFormatter::ROUND_UP,
|
||||
\NumberFormatter::ROUND_CEILING,
|
||||
),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class PasswordType extends AbstractType
|
||||
{
|
||||
@ -39,11 +40,11 @@ class PasswordType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'always_empty' => true,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class PercentType extends AbstractType
|
||||
{
|
||||
@ -28,26 +29,20 @@ class PercentType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'precision' => 0,
|
||||
'type' => 'fractional',
|
||||
'single_control' => true,
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllowedOptionValues()
|
||||
{
|
||||
return array(
|
||||
$resolver->setAllowedValues(array(
|
||||
'type' => array(
|
||||
'fractional',
|
||||
'integer',
|
||||
),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class RepeatedType extends AbstractType
|
||||
{
|
||||
@ -40,9 +41,9 @@ class RepeatedType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'type' => 'text',
|
||||
'options' => array(),
|
||||
'first_options' => array(),
|
||||
@ -50,7 +51,7 @@ class RepeatedType extends AbstractType
|
||||
'first_name' => 'first',
|
||||
'second_name' => 'second',
|
||||
'error_bubbling' => false,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToStringTransformer;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TextType extends AbstractType
|
||||
{
|
||||
@ -30,11 +31,11 @@ class TextType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'single_control' => true,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTra
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TimeType extends AbstractType
|
||||
{
|
||||
@ -138,13 +139,13 @@ class TimeType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$singleControl = function (Options $options) {
|
||||
return $options['widget'] === 'single_text';
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'hours' => range(0, 23),
|
||||
'minutes' => range(0, 59),
|
||||
'seconds' => range(0, 59),
|
||||
@ -164,15 +165,9 @@ class TimeType extends AbstractType
|
||||
// this option.
|
||||
'data_class' => null,
|
||||
'single_control' => $singleControl,
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllowedOptionValues()
|
||||
{
|
||||
return array(
|
||||
$resolver->setAllowedValues(array(
|
||||
'input' => array(
|
||||
'datetime',
|
||||
'string',
|
||||
@ -184,7 +179,7 @@ class TimeType extends AbstractType
|
||||
'text',
|
||||
'choice',
|
||||
),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TimezoneType extends AbstractType
|
||||
{
|
||||
@ -24,11 +25,11 @@ class TimezoneType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => self::getTimezones(),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class UrlType extends AbstractType
|
||||
{
|
||||
@ -28,11 +29,11 @@ class UrlType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'default_protocol' => 'http',
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
@ -81,14 +82,14 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'csrf_protection' => $this->defaultEnabled,
|
||||
'csrf_field_name' => $this->defaultFieldName,
|
||||
'csrf_provider' => $this->defaultCsrfProvider,
|
||||
'intention' => 'unknown',
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper;
|
||||
use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener;
|
||||
use Symfony\Component\Validator\ValidatorInterface;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
@ -72,14 +73,14 @@ class FormTypeValidatorExtension extends AbstractTypeExtension
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
// BC clause
|
||||
$constraints = function (Options $options) {
|
||||
return $options['validation_constraint'];
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'error_mapping' => array(),
|
||||
'validation_groups' => null,
|
||||
// "validation_constraint" is deprecated. Use "constraints".
|
||||
@ -89,7 +90,7 @@ class FormTypeValidatorExtension extends AbstractTypeExtension
|
||||
'invalid_message' => 'This value is not valid.',
|
||||
'extra_fields_message' => 'This form should not contain extra fields.',
|
||||
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Extension\Validator\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
@ -22,16 +23,16 @@ class RepeatedTypeValidatorExtension extends AbstractTypeExtension
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
// Map errors to the first field
|
||||
$errorMapping = function (Options $options) {
|
||||
return array('.' => $options['first_name']);
|
||||
};
|
||||
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'error_mapping' => $errorMapping,
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,16 +185,12 @@ class FormFactory implements FormFactoryInterface
|
||||
// Merge the default options of all types to an array of default
|
||||
// options. Default options of children override default options
|
||||
// of parents.
|
||||
$typeOptions = $type->getDefaultOptions();
|
||||
$optionsResolver->setDefaults($typeOptions);
|
||||
$optionsResolver->addAllowedValues($type->getAllowedOptionValues());
|
||||
$knownOptions = array_merge($knownOptions, array_keys($typeOptions));
|
||||
/* @var FormTypeInterface $type */
|
||||
$type->setDefaultOptions($optionsResolver);
|
||||
|
||||
foreach ($type->getExtensions() as $typeExtension) {
|
||||
$extensionOptions = $typeExtension->getDefaultOptions();
|
||||
$optionsResolver->setDefaults($extensionOptions);
|
||||
$optionsResolver->addAllowedValues($typeExtension->getAllowedOptionValues());
|
||||
$knownOptions = array_merge($knownOptions, array_keys($extensionOptions));
|
||||
/* @var FormTypeExtensionInterface $typeExtension */
|
||||
$typeExtension->setDefaultOptions($optionsResolver);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +198,13 @@ class FormFactory implements FormFactoryInterface
|
||||
$type = end($types);
|
||||
|
||||
// Validate options required by the factory
|
||||
$diff = array_diff(self::$requiredOptions, $knownOptions);
|
||||
$diff = array();
|
||||
|
||||
foreach (self::$requiredOptions as $requiredOption) {
|
||||
if (!$optionsResolver->isKnown($requiredOption)) {
|
||||
$diff[] = $requiredOption;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($diff) > 0) {
|
||||
throw new TypeDefinitionException(sprintf('Type "%s" should support the option(s) "%s"', $type->getName(), implode('", "', $diff)));
|
||||
|
@ -11,6 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface FormTypeExtensionInterface
|
||||
{
|
||||
/**
|
||||
@ -53,19 +58,11 @@ interface FormTypeExtensionInterface
|
||||
function buildViewBottomUp(FormView $view, FormInterface $form);
|
||||
|
||||
/**
|
||||
* Overrides the default options form the extended type.
|
||||
* Overrides the default options from the extended type.
|
||||
*
|
||||
* @return array
|
||||
* @param OptionsResolver $resolver The resolver for the options.
|
||||
*/
|
||||
function getDefaultOptions();
|
||||
|
||||
/**
|
||||
* Returns the allowed option values for each option (if any).
|
||||
*
|
||||
* @return array The allowed option values
|
||||
*/
|
||||
function getAllowedOptionValues();
|
||||
|
||||
function setDefaultOptions(OptionsResolver $resolver);
|
||||
|
||||
/**
|
||||
* Returns the name of the type being extended.
|
||||
|
@ -11,6 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface FormTypeInterface
|
||||
{
|
||||
/**
|
||||
@ -73,18 +78,11 @@ interface FormTypeInterface
|
||||
function createBuilder($name, FormFactoryInterface $factory, array $options);
|
||||
|
||||
/**
|
||||
* Returns the default options for this type.
|
||||
* Sets the default options for this type.
|
||||
*
|
||||
* @return array The default options
|
||||
* @param OptionsResolver $resolver The resolver for the options.
|
||||
*/
|
||||
function getDefaultOptions();
|
||||
|
||||
/**
|
||||
* Returns the allowed option values for each option (if any).
|
||||
*
|
||||
* @return array The allowed option values
|
||||
*/
|
||||
function getAllowedOptionValues();
|
||||
function setDefaultOptions(OptionsResolver $resolver);
|
||||
|
||||
/**
|
||||
* Returns the name of the parent type.
|
||||
|
@ -4,6 +4,7 @@ namespace Symfony\Component\Form\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AuthorType extends AbstractType
|
||||
{
|
||||
@ -20,10 +21,10 @@ class AuthorType extends AbstractType
|
||||
return 'author';
|
||||
}
|
||||
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -178,15 +178,6 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$type->expects($this->any())
|
||||
->method('getExtensions')
|
||||
->will($this->returnValue(array()));
|
||||
$type->expects($this->any())
|
||||
->method('getAllowedOptionValues')
|
||||
->will($this->returnValue(array()));
|
||||
$type->expects($this->any())
|
||||
->method('getDefaultOptions')
|
||||
->will($this->returnValue(array(
|
||||
'required' => false,
|
||||
'max_length' => null,
|
||||
)));
|
||||
|
||||
$this->extension1->addType($type);
|
||||
|
||||
@ -205,15 +196,6 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$type->expects($this->any())
|
||||
->method('getExtensions')
|
||||
->will($this->returnValue(array()));
|
||||
$type->expects($this->any())
|
||||
->method('getAllowedOptionValues')
|
||||
->will($this->returnValue(array()));
|
||||
$type->expects($this->any())
|
||||
->method('getDefaultOptions')
|
||||
->will($this->returnValue(array(
|
||||
'data' => null,
|
||||
'max_length' => null,
|
||||
)));
|
||||
|
||||
$this->extension1->addType($type);
|
||||
|
||||
@ -232,15 +214,6 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$type->expects($this->any())
|
||||
->method('getExtensions')
|
||||
->will($this->returnValue(array()));
|
||||
$type->expects($this->any())
|
||||
->method('getAllowedOptionValues')
|
||||
->will($this->returnValue(array()));
|
||||
$type->expects($this->any())
|
||||
->method('getDefaultOptions')
|
||||
->will($this->returnValue(array(
|
||||
'data' => null,
|
||||
'required' => false,
|
||||
)));
|
||||
|
||||
$this->extension1->addType($type);
|
||||
|
||||
@ -259,16 +232,6 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$type->expects($this->any())
|
||||
->method('getExtensions')
|
||||
->will($this->returnValue(array()));
|
||||
$type->expects($this->any())
|
||||
->method('getAllowedOptionValues')
|
||||
->will($this->returnValue(array()));
|
||||
$type->expects($this->any())
|
||||
->method('getDefaultOptions')
|
||||
->will($this->returnValue(array(
|
||||
'data' => null,
|
||||
'required' => false,
|
||||
'max_length' => null,
|
||||
)));
|
||||
$type->expects($this->any())
|
||||
->method('createBuilder')
|
||||
->will($this->returnValue(null));
|
||||
|
Reference in New Issue
Block a user