Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 621b769

Browse files
committed
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 ------- 84f5de9 mix attr options between type-guess options and user options
2 parents 1542925 + 84f5de9 commit 621b769

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Symfony/Component/Form/FormFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ public function createBuilderForProperty($class, $property, $data = null, array
126126

127127
// user options may override guessed options
128128
if ($typeGuess) {
129-
$options = array_merge($typeGuess->getOptions(), $options);
129+
$attrs = array();
130+
$typeGuessOptions = $typeGuess->getOptions();
131+
if (isset($typeGuessOptions['attr']) && isset($options['attr'])) {
132+
$attrs = array('attr' => array_merge($typeGuessOptions['attr'], $options['attr']));
133+
}
134+
135+
$options = array_merge($typeGuessOptions, $options, $attrs);
130136
}
131137

132138
return $this->createNamedBuilder($property, $type, $data, $options);

src/Symfony/Component/Form/Tests/FormFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,15 @@ public function testOptionsCanBeOverridden()
450450
->with('Application\Author', 'firstName')
451451
->will($this->returnValue(new TypeGuess(
452452
'text',
453-
array('attr' => array('maxlength' => 10)),
453+
array('attr' => array('class' => 'foo', 'maxlength' => 10)),
454454
Guess::MEDIUM_CONFIDENCE
455455
)));
456456

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

459459
$factory->expects($this->once())
460460
->method('createNamedBuilder')
461-
->with('firstName', 'text', null, array('attr' => array('maxlength' => 11)))
461+
->with('firstName', 'text', null, array('attr' => array('class' => 'foo', 'maxlength' => 11)))
462462
->will($this->returnValue('builderInstance'));
463463

464464
$this->builder = $factory->createBuilderForProperty(

0 commit comments

Comments
 (0)