Skip to content

Commit f4fc2e3

Browse files
committed
Fix the configurability of CoreExtension deps in standalone usage
When using the Forms entrypoint to configure the component, there was no chance to configure dependencies of the CoreExtension, as the one registered without argument was first and would win. The builder now delays the prepending of the CoreExtension to do it only if the CoreExtension is not registered explicitly.
1 parent c82e2df commit f4fc2e3

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/Symfony/Component/Form/FormFactoryBuilder.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
namespace Symfony\Component\Form;
1313

14+
use Symfony\Component\Form\Extension\Core\CoreExtension;
15+
1416
/**
1517
* The default implementation of FormFactoryBuilderInterface.
1618
*
1719
* @author Bernhard Schussek <bschussek@gmail.com>
1820
*/
1921
class FormFactoryBuilder implements FormFactoryBuilderInterface
2022
{
23+
private $forceCoreExtension;
24+
2125
/**
2226
* @var ResolvedFormTypeFactoryInterface
2327
*/
@@ -43,6 +47,14 @@ class FormFactoryBuilder implements FormFactoryBuilderInterface
4347
*/
4448
private $typeGuessers = [];
4549

50+
/**
51+
* @param bool $forceCoreExtension
52+
*/
53+
public function __construct($forceCoreExtension = false)
54+
{
55+
$this->forceCoreExtension = $forceCoreExtension;
56+
}
57+
4658
/**
4759
* {@inheritdoc}
4860
*/
@@ -144,6 +156,21 @@ public function getFormFactory()
144156
{
145157
$extensions = $this->extensions;
146158

159+
if ($this->forceCoreExtension) {
160+
$hasCoreExtension = false;
161+
162+
foreach ($extensions as $extension) {
163+
if ($extension instanceof CoreExtension) {
164+
$hasCoreExtension = true;
165+
break;
166+
}
167+
}
168+
169+
if (!$hasCoreExtension) {
170+
array_unshift($extensions, new CoreExtension());
171+
}
172+
}
173+
147174
if (\count($this->types) > 0 || \count($this->typeExtensions) > 0 || \count($this->typeGuessers) > 0) {
148175
if (\count($this->typeGuessers) > 1) {
149176
$typeGuesser = new FormTypeGuesserChain($this->typeGuessers);

src/Symfony/Component/Form/Forms.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Form;
1313

14-
use Symfony\Component\Form\Extension\Core\CoreExtension;
15-
1614
/**
1715
* Entry point of the Form component.
1816
*
@@ -105,10 +103,7 @@ public static function createFormFactory()
105103
*/
106104
public static function createFormFactoryBuilder()
107105
{
108-
$builder = new FormFactoryBuilder();
109-
$builder->addExtension(new CoreExtension());
110-
111-
return $builder;
106+
return new FormFactoryBuilder(true);
112107
}
113108

114109
/**

0 commit comments

Comments
 (0)