Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
mix attr options between type-guess options and user options
  • Loading branch information
yceruto committed May 29, 2017
commit 84f5de902d0dedfa94f70a1e65124f2bbdd6400c
8 changes: 7 additions & 1 deletion src/Symfony/Component/Form/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ public function createBuilderForProperty($class, $property, $data = null, array

// 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);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Tests/FormFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,15 @@ public function testOptionsCanBeOverridden()
->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
)));

$factory = $this->getMockFactory(array('createNamedBuilder'));

$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(
Expand Down