This tool will helps you upgrade your Symfony2 project.
1
stars
0
forks
source link
Methods getDefaultOptions and getAllowedOptionValues of FormTypeInterface and FormTypeExtensionInterface are deprecated and will be removed in Symfony 2.3. #35
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 OptionsResolverInterface 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(OptionsResolverInterface $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(OptionsResolverInterface $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.
The following methods of
FormTypeInterface
andFormTypeExtensionInterface
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 OptionsResolverInterface instance and with that a lot more power.Before:
After:
You can specify options that depend on other options using closures.
Before:
After:
The second argument
$value
contains the current default value and does not have to be specified if not needed.