Fix the configurability of CoreExtension deps in standalone usage
This commit is contained in:
parent
c82e2df9ff
commit
934118b131
@ -69,7 +69,7 @@ class CoreExtension extends AbstractExtension
|
||||
new Type\TimeType(),
|
||||
new Type\TimezoneType(),
|
||||
new Type\UrlType(),
|
||||
new Type\FileType(),
|
||||
new Type\FileType($this->translator),
|
||||
new Type\ButtonType(),
|
||||
new Type\SubmitType(),
|
||||
new Type\ResetType(),
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\CoreExtension;
|
||||
|
||||
/**
|
||||
* The default implementation of FormFactoryBuilderInterface.
|
||||
*
|
||||
@ -18,6 +20,8 @@ namespace Symfony\Component\Form;
|
||||
*/
|
||||
class FormFactoryBuilder implements FormFactoryBuilderInterface
|
||||
{
|
||||
private $forceCoreExtension;
|
||||
|
||||
/**
|
||||
* @var ResolvedFormTypeFactoryInterface
|
||||
*/
|
||||
@ -43,6 +47,14 @@ class FormFactoryBuilder implements FormFactoryBuilderInterface
|
||||
*/
|
||||
private $typeGuessers = [];
|
||||
|
||||
/**
|
||||
* @param bool $forceCoreExtension
|
||||
*/
|
||||
public function __construct($forceCoreExtension = false)
|
||||
{
|
||||
$this->forceCoreExtension = $forceCoreExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -144,6 +156,21 @@ class FormFactoryBuilder implements FormFactoryBuilderInterface
|
||||
{
|
||||
$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);
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\CoreExtension;
|
||||
|
||||
/**
|
||||
* Entry point of the Form component.
|
||||
*
|
||||
@ -105,10 +103,7 @@ final class Forms
|
||||
*/
|
||||
public static function createFormFactoryBuilder()
|
||||
{
|
||||
$builder = new FormFactoryBuilder();
|
||||
$builder->addExtension(new CoreExtension());
|
||||
|
||||
return $builder;
|
||||
return new FormFactoryBuilder(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user