Skip to content

Commit

Permalink
Fix the configurability of CoreExtension deps in standalone usage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stof committed Apr 7, 2019
1 parent c82e2df commit 8b024dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/Symfony/Component/Form/FormFactoryBuilder.php
Expand Up @@ -11,13 +11,17 @@

namespace Symfony\Component\Form;

use Symfony\Component\Form\Extension\Core\CoreExtension;

/**
* The default implementation of FormFactoryBuilderInterface.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormFactoryBuilder implements FormFactoryBuilderInterface
{
private $forceCoreExtension;

/**
* @var ResolvedFormTypeFactoryInterface
*/
Expand All @@ -43,6 +47,14 @@ class FormFactoryBuilder implements FormFactoryBuilderInterface
*/
private $typeGuessers = [];

/**
* @param bool $forceCoreExtension
*/
public function __construct($forceCoreExtension = false)
{
$this->forceCoreExtension = $forceCoreExtension;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -144,6 +156,21 @@ public function getFormFactory()
{
$extensions = $this->extensions;

if ($this->forceCoreExtension) {
$hasCoreExtension = false;

foreach ($extensions as $extension) {
if ($extension instanceof CoreExtension) {
$hasCoreExtension = true;
break;
}
}

if (!$hasCoreExtension) {
array_unshift($extensions, new CoreExtension());
}
}

if (\count($this->types) > 0 || \count($this->typeExtensions) > 0 || \count($this->typeGuessers) > 0) {
if (\count($this->typeGuessers) > 1) {
$typeGuesser = new FormTypeGuesserChain($this->typeGuessers);
Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Component/Form/Forms.php
Expand Up @@ -105,10 +105,7 @@ public static function createFormFactory()
*/
public static function createFormFactoryBuilder()
{
$builder = new FormFactoryBuilder();
$builder->addExtension(new CoreExtension());

return $builder;
return new FormFactoryBuilder(true);
}

/**
Expand Down

0 comments on commit 8b024dd

Please sign in to comment.