Merge branch '2.7' into 2.8

* 2.7:
  [TwigBridge] Fix namespaced classes
  mix attr options between type-guess options and user options
This commit is contained in:
Fabien Potencier 2017-06-05 19:49:00 -07:00
commit 419556ff87
3 changed files with 14 additions and 6 deletions

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Twig\NodeVisitor;
use Symfony\Bridge\Twig\Node\TransNode; use Symfony\Bridge\Twig\Node\TransNode;
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode; use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
use Twig\Environment; use Twig\Environment;
use Twig\Node\BlockNode;
use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\AssignNameExpression; use Twig\Node\Expression\AssignNameExpression;
use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\ConstantExpression;
@ -21,6 +22,7 @@ use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\NameExpression; use Twig\Node\Expression\NameExpression;
use Twig\Node\ModuleNode; use Twig\Node\ModuleNode;
use Twig\Node\Node; use Twig\Node\Node;
use Twig\Node\SetNode;
use Twig\NodeVisitor\AbstractNodeVisitor; use Twig\NodeVisitor\AbstractNodeVisitor;
/** /**
@ -48,7 +50,7 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
*/ */
protected function doEnterNode(Node $node, Environment $env) 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(); $this->scope = $this->scope->enter();
} }
@ -62,7 +64,7 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
$name = new AssignNameExpression($var, $node->getTemplateLine()); $name = new AssignNameExpression($var, $node->getTemplateLine());
$this->scope->set('domain', new NameExpression($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());
} }
} }
@ -104,7 +106,7 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
return false; return false;
} }
if ($node instanceof Node_Block || $node instanceof ModuleNode) { if ($node instanceof BlockNode || $node instanceof ModuleNode) {
$this->scope = $this->scope->leave(); $this->scope = $this->scope->leave();
} }

View File

@ -153,7 +153,13 @@ class FormFactory implements FormFactoryInterface
// user options may override guessed options // user options may override guessed options
if ($typeGuess) { 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); return $this->createNamedBuilder($property, $type, $data, $options);

View File

@ -686,7 +686,7 @@ class FormFactoryTest extends TestCase
->with('Application\Author', 'firstName') ->with('Application\Author', 'firstName')
->will($this->returnValue(new TypeGuess( ->will($this->returnValue(new TypeGuess(
'Symfony\Component\Form\Extension\Core\Type\TextType', 'Symfony\Component\Form\Extension\Core\Type\TextType',
array('attr' => array('maxlength' => 10)), array('attr' => array('class' => 'foo', 'maxlength' => 10)),
Guess::MEDIUM_CONFIDENCE Guess::MEDIUM_CONFIDENCE
))); )));
@ -694,7 +694,7 @@ class FormFactoryTest extends TestCase
$factory->expects($this->once()) $factory->expects($this->once())
->method('createNamedBuilder') ->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')); ->will($this->returnValue('builderInstance'));
$this->builder = $factory->createBuilderForProperty( $this->builder = $factory->createBuilderForProperty(