Skip to content

Commit a86a38a

Browse files
committed
[Form] Add form type guesser for EnumType
1 parent 06a94e2 commit a86a38a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
use Symfony\Component\Filesystem\Filesystem;
8484
use Symfony\Component\Finder\Finder;
8585
use Symfony\Component\Finder\Glob;
86+
use Symfony\Component\Form\EnumFormTypeGuesser;
8687
use Symfony\Component\Form\Extension\HtmlSanitizer\Type\TextTypeHtmlSanitizerExtension;
8788
use Symfony\Component\Form\Form;
8889
use Symfony\Component\Form\FormTypeExtensionInterface;
@@ -880,6 +881,10 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
880881
{
881882
$loader->load('form.php');
882883

884+
if (!class_exists(EnumFormTypeGuesser::class)) {
885+
$container->removeDefinition('form.type_guesser.enum_type');
886+
}
887+
883888
if (null === $config['form']['csrf_protection']['enabled']) {
884889
$this->writeConfigEnabled('form.csrf_protection', $config['csrf_protection']['enabled'], $config['form']['csrf_protection']);
885890
}

Resources/config/form.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
1515
use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;
1616
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
17+
use Symfony\Component\Form\EnumFormTypeGuesser;
1718
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
1819
use Symfony\Component\Form\Extension\Core\Type\ColorType;
1920
use Symfony\Component\Form\Extension\Core\Type\FileType;
@@ -76,6 +77,9 @@
7677
->args([service('validator.mapping.class_metadata_factory')])
7778
->tag('form.type_guesser')
7879

80+
->set('form.type_guesser.enum_type', EnumFormTypeGuesser::class)
81+
->tag('form.type_guesser')
82+
7983
->alias('form.property_accessor', 'property_accessor')
8084

8185
->set('form.choice_list_factory.default', DefaultChoiceListFactory::class)

0 commit comments

Comments
 (0)