Skip to content

Commit

Permalink
Merge branch '2.8' into 3.2
Browse files Browse the repository at this point in the history
* 2.8:
  [TwigBridge] Fix namespaced classes
  mix attr options between type-guess options and user options
  • Loading branch information
fabpot committed Jun 6, 2017
2 parents 81a5057 + 419556f commit c297144
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Expand Up @@ -14,13 +14,15 @@
use Symfony\Bridge\Twig\Node\TransNode;
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
use Twig\Environment;
use Twig\Node\BlockNode;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\AssignNameExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\ModuleNode;
use Twig\Node\Node;
use Twig\Node\SetNode;
use Twig\NodeVisitor\AbstractNodeVisitor;

/**
Expand Down Expand Up @@ -48,7 +50,7 @@ public function __construct()
*/
protected function doEnterNode(Node $node, Environment $env)
{
if ($node instanceof Node_Block || $node instanceof ModuleNode) {
if ($node instanceof BlockNode || $node instanceof ModuleNode) {
$this->scope = $this->scope->enter();
}

Expand All @@ -62,7 +64,7 @@ protected function doEnterNode(Node $node, Environment $env)
$name = new AssignNameExpression($var, $node->getTemplateLine());
$this->scope->set('domain', new NameExpression($var, $node->getTemplateLine()));

return new Node_Set(false, new Node(array($name)), new Node(array($node->getNode('expr'))), $node->getTemplateLine());
return new SetNode(false, new Node(array($name)), new Node(array($node->getNode('expr'))), $node->getTemplateLine());
}
}

Expand Down Expand Up @@ -104,7 +106,7 @@ protected function doLeaveNode(Node $node, Environment $env)
return false;
}

if ($node instanceof Node_Block || $node instanceof ModuleNode) {
if ($node instanceof BlockNode || $node instanceof ModuleNode) {
$this->scope = $this->scope->leave();
}

Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/Form/FormFactory.php
Expand Up @@ -124,7 +124,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 @@ -316,15 +316,15 @@ public function testOptionsCanBeOverridden()
->with('Application\Author', 'firstName')
->will($this->returnValue(new TypeGuess(
'Symfony\Component\Form\Extension\Core\Type\TextType',
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', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array('attr' => array('maxlength' => 11)))
->with('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array('attr' => array('class' => 'foo', 'maxlength' => 11)))
->will($this->returnValue('builderInstance'));

$this->builder = $factory->createBuilderForProperty(
Expand Down

0 comments on commit c297144

Please sign in to comment.