Skip to content

Commit b5ec089

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [TwigBridge] Fix namespaced classes mix attr options between type-guess options and user options
2 parents fbd6375 + 66dbfdc commit b5ec089

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

FormFactory.php

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

154154
// user options may override guessed options
155155
if ($typeGuess) {
156-
$options = array_merge($typeGuess->getOptions(), $options);
156+
$attrs = array();
157+
$typeGuessOptions = $typeGuess->getOptions();
158+
if (isset($typeGuessOptions['attr']) && isset($options['attr'])) {
159+
$attrs = array('attr' => array_merge($typeGuessOptions['attr'], $options['attr']));
160+
}
161+
162+
$options = array_merge($typeGuessOptions, $options, $attrs);
157163
}
158164

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

Tests/FormFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,15 +686,15 @@ public function testOptionsCanBeOverridden()
686686
->with('Application\Author', 'firstName')
687687
->will($this->returnValue(new TypeGuess(
688688
'Symfony\Component\Form\Extension\Core\Type\TextType',
689-
array('attr' => array('maxlength' => 10)),
689+
array('attr' => array('class' => 'foo', 'maxlength' => 10)),
690690
Guess::MEDIUM_CONFIDENCE
691691
)));
692692

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

695695
$factory->expects($this->once())
696696
->method('createNamedBuilder')
697-
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array('attr' => array('maxlength' => 11)))
697+
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array('attr' => array('class' => 'foo', 'maxlength' => 11)))
698698
->will($this->returnValue('builderInstance'));
699699

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

0 commit comments

Comments
 (0)