Skip to content

Commit 6df8bad

Browse files
minor #16761 [Form] Cleanup (nicolas-grekas)
This PR was merged into the 2.8 branch. Discussion ---------- [Form] Cleanup | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - ping @stof Commits ------- fd8e882 [Form] Cleanup
2 parents 0055887 + fd8e882 commit 6df8bad

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

src/Symfony/Component/Form/FormFactory.php

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,48 +62,29 @@ public function createForProperty($class, $property, $data = null, array $option
6262
public function createBuilder($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = array())
6363
{
6464
$name = null;
65-
$typeName = null;
6665

6766
if ($type instanceof ResolvedFormTypeInterface) {
68-
if (method_exists($type, 'getBlockPrefix')) {
69-
// As of Symfony 3.0, the block prefix of the type is used as
70-
// default name
71-
$name = $type->getBlockPrefix();
72-
} else {
73-
// BC
74-
$typeName = $type->getName();
75-
}
67+
$typeObject = $type;
7668
} elseif ($type instanceof FormTypeInterface) {
77-
if (method_exists($type, 'getBlockPrefix')) {
78-
// As of Symfony 3.0, the block prefix of the type is used as
79-
// default name
80-
$name = $type->getBlockPrefix();
81-
} else {
82-
// BC
83-
$typeName = $type->getName();
84-
}
69+
$typeObject = $type;
8570
} elseif (is_string($type)) {
86-
$resolvedType = $this->registry->getType($type);
87-
if (method_exists($resolvedType, 'getBlockPrefix')) {
88-
// As of Symfony 3.0, the block prefix of the type is used as
89-
// default name
90-
$name = $resolvedType->getBlockPrefix();
91-
} else {
92-
// BC
93-
$typeName = $type;
94-
}
71+
$typeObject = $this->registry->getType($type);
72+
$name = $type;
9573
} else {
9674
throw new UnexpectedTypeException($type, 'string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface');
9775
}
9876

99-
// BC when there is no block prefix
100-
if (null === $name) {
101-
if (false === strpos($typeName, '\\')) {
102-
// No FQCN - leave unchanged for BC
103-
$name = $typeName;
104-
} else {
77+
if (method_exists($typeObject, 'getBlockPrefix')) {
78+
// As of Symfony 3.0, the block prefix of the type is used as default name
79+
$name = $typeObject->getBlockPrefix();
80+
} else {
81+
// BC when there is no block prefix
82+
if (null === $name) {
83+
$name = $typeObject->getName();
84+
}
85+
if (false !== strpos($name, '\\')) {
10586
// FQCN
106-
$name = StringUtil::fqcnToBlockPrefix($typeName);
87+
$name = StringUtil::fqcnToBlockPrefix($name);
10788
}
10889
}
10990

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ public function testCreateUsesBlockPrefixIfTypeGivenAsString()
341341
$this->assertSame('FORM', $this->factory->create('TYPE', null, $options));
342342
}
343343

344+
/**
345+
* @group legacy
346+
*/
344347
public function testCreateUsesTypeNameIfTypeGivenAsString()
345348
{
346349
$options = array('a' => '1', 'b' => '2');
@@ -372,6 +375,9 @@ public function testCreateUsesTypeNameIfTypeGivenAsString()
372375
$this->assertSame('FORM', $this->factory->create('TYPE', null, $options));
373376
}
374377

378+
/**
379+
* @group legacy
380+
*/
375381
public function testCreateStripsNamespaceOffTypeName()
376382
{
377383
$options = array('a' => '1', 'b' => '2');
@@ -403,6 +409,9 @@ public function testCreateStripsNamespaceOffTypeName()
403409
$this->assertSame('FORM', $this->factory->create('Vendor\Name\Space\UserForm', null, $options));
404410
}
405411

412+
/**
413+
* @group legacy
414+
*/
406415
public function testLegacyCreateStripsNamespaceOffTypeNameAccessByFQCN()
407416
{
408417
$options = array('a' => '1', 'b' => '2');
@@ -434,6 +443,9 @@ public function testLegacyCreateStripsNamespaceOffTypeNameAccessByFQCN()
434443
$this->assertSame('FORM', $this->factory->create('userform', null, $options));
435444
}
436445

446+
/**
447+
* @group legacy
448+
*/
437449
public function testCreateStripsTypeSuffixOffTypeName()
438450
{
439451
$options = array('a' => '1', 'b' => '2');
@@ -465,6 +477,9 @@ public function testCreateStripsTypeSuffixOffTypeName()
465477
$this->assertSame('FORM', $this->factory->create('Vendor\Name\Space\UserType', null, $options));
466478
}
467479

480+
/**
481+
* @group legacy
482+
*/
468483
public function testCreateDoesNotStripTypeSuffixIfResultEmpty()
469484
{
470485
$options = array('a' => '1', 'b' => '2');
@@ -496,6 +511,9 @@ public function testCreateDoesNotStripTypeSuffixIfResultEmpty()
496511
$this->assertSame('FORM', $this->factory->create('Vendor\Name\Space\Type', null, $options));
497512
}
498513

514+
/**
515+
* @group legacy
516+
*/
499517
public function testCreateConvertsTypeToUnderscoreSyntax()
500518
{
501519
$options = array('a' => '1', 'b' => '2');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy