bug #22936 [Form] Mix attr option between guessed options and user options (yceruto)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] Mix attr option between guessed options and user options

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19871
| License       | MIT

Commits
-------

84f5de902d mix attr options between type-guess options and user options
This commit is contained in:
Fabien Potencier 2017-06-03 08:53:19 -07:00
commit 621b7698fb
2 changed files with 9 additions and 3 deletions

View File

@ -126,7 +126,13 @@ class FormFactory implements FormFactoryInterface
// user options may override guessed options
if ($typeGuess) {
$options = array_merge($typeGuess->getOptions(), $options);
$attrs = array();
$typeGuessOptions = $typeGuess->getOptions();
if (isset($typeGuessOptions['attr']) && isset($options['attr'])) {
$attrs = array('attr' => array_merge($typeGuessOptions['attr'], $options['attr']));
}
$options = array_merge($typeGuessOptions, $options, $attrs);
}
return $this->createNamedBuilder($property, $type, $data, $options);

View File

@ -450,7 +450,7 @@ class FormFactoryTest extends TestCase
->with('Application\Author', 'firstName')
->will($this->returnValue(new TypeGuess(
'text',
array('attr' => array('maxlength' => 10)),
array('attr' => array('class' => 'foo', 'maxlength' => 10)),
Guess::MEDIUM_CONFIDENCE
)));
@ -458,7 +458,7 @@ class FormFactoryTest extends TestCase
$factory->expects($this->once())
->method('createNamedBuilder')
->with('firstName', 'text', null, array('attr' => array('maxlength' => 11)))
->with('firstName', 'text', null, array('attr' => array('class' => 'foo', 'maxlength' => 11)))
->will($this->returnValue('builderInstance'));
$this->builder = $factory->createBuilderForProperty(