sonata-project/SonataAdminBundle — Issue #440: Incorrect options merging in FormMapper::add()
Author: lu4e3ar
Created: 2011-12-07 09:10:43+00:00
State: open

In https://github.com/sonata-project/SonataAdminBundle/blob/master/Form/FormMapper.php#L104

```php
$options = array_merge($options, $this->formContractor->getDefaultOptions($type, $fieldDescription));
```

This code means that default options have higher precedence than user-defined options.
It obviously wrong.

Example of correct options merging in Symfony FormFactory ( https://github.com/symfony/Form/blob/master/FormFactory.php#L240 )
```php
$options = array_replace($defaultOptions, $options);
```

Example of problem consequences :
1. I want to define type_options for sonata_type_collection ( CollectionType ).
2. FormMapper::add() try to get default options on line in example above
3. Default type_options for sonata_type_collection be found in FormContractor::getDefaultOptions() ( SonataDoctrineORMAdminBundle ) https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/master/Builder/FormContractor.php#L135
4. Default options from FormContractor::getDefaultOptions() overwrite my options and i have no way to pass my options