Skip to content

Commit 1c3432f

Browse files
committed
feature #61297 [Form] Add form type guesser for EnumType (mttsch)
This PR was merged into the 7.4 branch. Discussion ---------- [Form] Add form type guesser for `EnumType` | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #61272 | License | MIT This new form type guesser guesses the form type of an enum property and also sets the `class` option of the `EnumType` to the relevant enum name. Commits ------- 9e8a9235caa [Form] Add form type guesser for `EnumType`
2 parents e8540fb + a86a38a commit 1c3432f

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;
@@ -881,6 +882,10 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
881882
{
882883
$loader->load('form.php');
883884

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

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)