Fix BC for the default root form name
The block prefix is used, to match the previous behavior when using a custom block prefix.
This commit is contained in:
parent
9b6f592542
commit
0a54d098a9
@ -74,15 +74,29 @@ class FormFactory implements FormFactoryInterface
|
|||||||
$typeName = $type->getName();
|
$typeName = $type->getName();
|
||||||
}
|
}
|
||||||
} elseif ($type instanceof FormTypeInterface) {
|
} elseif ($type instanceof FormTypeInterface) {
|
||||||
// BC
|
if (method_exists($type, 'getBlockPrefix')) {
|
||||||
$typeName = $type->getName();
|
// As of Symfony 3.0, the block prefix of the type is used as
|
||||||
|
// default name
|
||||||
|
$name = $type->getBlockPrefix();
|
||||||
|
} else {
|
||||||
|
// BC
|
||||||
|
$typeName = $type->getName();
|
||||||
|
}
|
||||||
} elseif (is_string($type)) {
|
} elseif (is_string($type)) {
|
||||||
// BC
|
$resolvedType = $this->registry->getType($type);
|
||||||
$typeName = $type;
|
if (method_exists($resolvedType, 'getBlockPrefix')) {
|
||||||
|
// As of Symfony 3.0, the block prefix of the type is used as
|
||||||
|
// default name
|
||||||
|
$name = $resolvedType->getBlockPrefix();
|
||||||
|
} else {
|
||||||
|
// BC
|
||||||
|
$typeName = $type;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UnexpectedTypeException($type, 'string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface');
|
throw new UnexpectedTypeException($type, 'string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BC when there is no block prefix
|
||||||
if (null === $name) {
|
if (null === $name) {
|
||||||
if (false === strpos($typeName, '\\')) {
|
if (false === strpos($typeName, '\\')) {
|
||||||
// No FQCN - leave unchanged for BC
|
// No FQCN - leave unchanged for BC
|
||||||
|
@ -302,13 +302,52 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->factory->create(new \stdClass());
|
$this->factory->create(new \stdClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreateUsesBlockPrefixIfTypeGivenAsString()
|
||||||
|
{
|
||||||
|
$options = array('a' => '1', 'b' => '2');
|
||||||
|
$resolvedOptions = array('a' => '2', 'b' => '3');
|
||||||
|
|
||||||
|
// the interface does not have the method, so use the real class
|
||||||
|
$resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$resolvedType->expects($this->any())
|
||||||
|
->method('getBlockPrefix')
|
||||||
|
->willReturn('TYPE_PREFIX');
|
||||||
|
|
||||||
|
$this->registry->expects($this->any())
|
||||||
|
->method('getType')
|
||||||
|
->with('TYPE')
|
||||||
|
->will($this->returnValue($resolvedType));
|
||||||
|
|
||||||
|
$resolvedType->expects($this->once())
|
||||||
|
->method('createBuilder')
|
||||||
|
->with($this->factory, 'TYPE_PREFIX', $options)
|
||||||
|
->will($this->returnValue($this->builder));
|
||||||
|
|
||||||
|
$this->builder->expects($this->any())
|
||||||
|
->method('getOptions')
|
||||||
|
->will($this->returnValue($resolvedOptions));
|
||||||
|
|
||||||
|
$resolvedType->expects($this->once())
|
||||||
|
->method('buildForm')
|
||||||
|
->with($this->builder, $resolvedOptions);
|
||||||
|
|
||||||
|
$this->builder->expects($this->once())
|
||||||
|
->method('getForm')
|
||||||
|
->will($this->returnValue('FORM'));
|
||||||
|
|
||||||
|
$this->assertSame('FORM', $this->factory->create('TYPE', null, $options));
|
||||||
|
}
|
||||||
|
|
||||||
public function testCreateUsesTypeNameIfTypeGivenAsString()
|
public function testCreateUsesTypeNameIfTypeGivenAsString()
|
||||||
{
|
{
|
||||||
$options = array('a' => '1', 'b' => '2');
|
$options = array('a' => '1', 'b' => '2');
|
||||||
$resolvedOptions = array('a' => '2', 'b' => '3');
|
$resolvedOptions = array('a' => '2', 'b' => '3');
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->getMockResolvedType();
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->any())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
->with('TYPE')
|
->with('TYPE')
|
||||||
->will($this->returnValue($resolvedType));
|
->will($this->returnValue($resolvedType));
|
||||||
@ -339,7 +378,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$resolvedOptions = array('a' => '2', 'b' => '3');
|
$resolvedOptions = array('a' => '2', 'b' => '3');
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->getMockResolvedType();
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->any())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
->with('Vendor\Name\Space\UserForm')
|
->with('Vendor\Name\Space\UserForm')
|
||||||
->will($this->returnValue($resolvedType));
|
->will($this->returnValue($resolvedType));
|
||||||
@ -370,7 +409,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$resolvedOptions = array('a' => '2', 'b' => '3');
|
$resolvedOptions = array('a' => '2', 'b' => '3');
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->getMockResolvedType();
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->any())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
->with('userform')
|
->with('userform')
|
||||||
->will($this->returnValue($resolvedType));
|
->will($this->returnValue($resolvedType));
|
||||||
@ -401,7 +440,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$resolvedOptions = array('a' => '2', 'b' => '3');
|
$resolvedOptions = array('a' => '2', 'b' => '3');
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->getMockResolvedType();
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->any())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
->with('Vendor\Name\Space\UserType')
|
->with('Vendor\Name\Space\UserType')
|
||||||
->will($this->returnValue($resolvedType));
|
->will($this->returnValue($resolvedType));
|
||||||
@ -432,7 +471,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$resolvedOptions = array('a' => '2', 'b' => '3');
|
$resolvedOptions = array('a' => '2', 'b' => '3');
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->getMockResolvedType();
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->any())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
->with('Vendor\Name\Space\Type')
|
->with('Vendor\Name\Space\Type')
|
||||||
->will($this->returnValue($resolvedType));
|
->will($this->returnValue($resolvedType));
|
||||||
@ -463,7 +502,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$resolvedOptions = array('a' => '2', 'b' => '3');
|
$resolvedOptions = array('a' => '2', 'b' => '3');
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->getMockResolvedType();
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->any())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
->with('Vendor\Name\Space\MyProfileHTMLType')
|
->with('Vendor\Name\Space\MyProfileHTMLType')
|
||||||
->will($this->returnValue($resolvedType));
|
->will($this->returnValue($resolvedType));
|
||||||
|
Reference in New Issue
Block a user