Skip to content

Commit

Permalink
bug #22936 [Form] Mix attr option between guessed options and user op…
Browse files Browse the repository at this point in the history
…tions (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
-------

84f5de9 mix attr options between type-guess options and user options
  • Loading branch information
fabpot committed Jun 3, 2017
2 parents 1542925 + 84f5de9 commit 621b769
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Symfony/Component/Form/FormFactory.php
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
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

0 comments on commit 621b769

Please sign in to comment.