Skip to content

Commit

Permalink
[nelmio#2104] Add support for Backed Enum as model in Symfony Forms
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-jovanovic-php committed May 29, 2023
1 parent ebe6f59 commit 9690fe7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ModelDescriber/FormModelDescriber.php
Expand Up @@ -199,7 +199,20 @@ private function findFormType(FormConfigInterface $config, OA\Schema $property)
break;
}

if ('choice' === $blockPrefix) {
if ('enum' === $blockPrefix || $config->getType()->getInnerType()->getBlockPrefix() === 'enum') {
$model = new Model(
new Type(Type::BUILTIN_TYPE_OBJECT, !$config->getOption('required'), $config->getOption('class')),
null,
$config->getOptions()
);
$ref = $this->modelRegistry->register($model);
if ($config->getOption('multiple')) {
$property->type = 'array';
$property->items = Util::createChild($property, OA\Items::class, ['ref' => $ref]);
} else {
$property->ref = $ref;
}
} elseif ('choice' === $blockPrefix) {
if ($config->getOption('multiple')) {
$property->type = 'array';
} else {
Expand Down

0 comments on commit 9690fe7

Please sign in to comment.