This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/UPGRADE-2.7.md
Fabien Potencier fef2bd4812 feature #12891 [Form] Deprecated setDefaultOptions() in favor of configureOptions() (peterrehm)
This PR was merged into the 2.7 branch.

Discussion
----------

[Form] Deprecated setDefaultOptions() in favor of configureOptions()

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   |
| Fixed tickets | #12782
| License       | MIT
| Doc PR        | symfony/symfony-docs#4786

This tries to provide a compatible API with the depreciation of the OptionResolverInterface. I would like to have this in 2.6.2 but I think that might not be possible? To me I think we should always provide an API where you do not need to use deprecated classes.

Also can you think of any way to trigger errors on the use of the deprecated setDefaultOptions() method? Since it is usually overwritten without calling the parent class this might be tricky. Maybe only in the resolver if we can check if actual options has been resolved in a call to setDefaultOptions.

Commits
-------

3d43cae Deprecated setDefaultOptions() in favor of configureOptions()
2015-01-18 15:06:44 +01:00

1.9 KiB

UPGRADE FROM 2.6 to 2.7

Router

  • Route conditions now support container parameters which can be injected into condition using %parameter% notation. Due to the fact that it works by replacing all parameters with their corresponding values before passing condition expression for compilation there can be BC breaks where you could already have used percentage symbols. Single percentage symbol usage is not affected in any way. Conflicts may occur where you might have used % as a modulo operator, here's an example: foo%bar%2 which would be compiled to $foo % $bar % 2 in 2.6 but in 2.7 you would get an error if bar parameter doesn't exist or unexpected result otherwise.

Form

  • In form types and extension overriding the "setDefaultOptions" of the AbstractType or AbstractExtensionType has been deprecated in favor of overriding the new "configureOptions" method.

    The method "setDefaultOptions(OptionsResolverInterface $resolver)" will be renamed in Symfony 3.0 to "configureOptions(OptionsResolver $resolver)".

    Before:

         use Symfony\Component\OptionsResolver\OptionsResolverInterface;
    
         class TaskType extends AbstractType
         {
             // ...
             public function setDefaultOptions(OptionsResolverInterface $resolver)
             {
                 $resolver->setDefaults(array(
                     'data_class' => 'AppBundle\Entity\Task',
                 ));
             }
         }
    

    After:

         use Symfony\Component\OptionsResolver\OptionsResolver;
    
         class TaskType extends AbstractType
         {
             // ...
             public function configureOptions(OptionsResolver $resolver)
             {
                 $resolver->setDefaults(array(
                     'data_class' => 'AppBundle\Entity\Task',
                 ));
             }
         }