mix attr options between type-guess options and user options

This commit is contained in:
Yonel Ceruto 2017-05-28 19:55:48 -04:00
parent 20485d1f9b
commit 84f5de902d
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(