8000 bug #30979 Fix the configurability of CoreExtension deps in standalon… · symfony/symfony@d8b03ee · GitHub
[go: up one dir, main page]

Skip to content

Commit d8b03ee

Browse files
bug #30979 Fix the configurability of CoreExtension deps in standalone usage (stof)
This PR was squashed before being merged into the 3.4 branch (closes #30979). Discussion ---------- Fix the configurability of CoreExtension deps in standalone usage | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | not yet, but will allow fixing them | Fixed tickets | n/a | License | MIT | Doc PR | n/a 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. We discovered that when trying to fix tests for the FileType, where we wanted to pass a Translator to it. Commits ------- 934118b Fix the configurability of CoreExtension deps in standalone usage
2 parents 77320cb + 934118b commit d8b03ee

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/Symfony/Component/Form/Extension/Core/CoreExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function loadTypes()
6969
new Type\TimeType(),
7070
new Type\TimezoneType(),
7171
new Type\UrlType(),
72-
new Type\FileType(),
72+
new Type\FileType($this->translator),
7373
new Type\ButtonType(),
7474
new Type\SubmitType(),
7575
new Type\ResetType(),

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)
0