diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..13566b81b0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/EasyAdminBundle-fork.iml b/.idea/EasyAdminBundle-fork.iml new file mode 100644 index 0000000000..486d44ac80 --- /dev/null +++ b/.idea/EasyAdminBundle-fork.iml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000000..97626ba454 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000000..576d84cdb9 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..5f3066799e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000000..21e1b12aad --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/symfony2.xml b/.idea/symfony2.xml new file mode 100644 index 0000000000..bd98e4094e --- /dev/null +++ b/.idea/symfony2.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..35eb1ddfbb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Field/Configurator/ChoiceConfigurator.php b/src/Field/Configurator/ChoiceConfigurator.php index 8db5e14430..03a6aad806 100644 --- a/src/Field/Configurator/ChoiceConfigurator.php +++ b/src/Field/Configurator/ChoiceConfigurator.php @@ -52,14 +52,13 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c $enumTypeClass = $field->getDoctrineMetadata()->get('enumType'); if (0 === \count($choices) && null !== $enumTypeClass && enum_exists($enumTypeClass)) { $choices = $enumTypeClass::cases(); - } elseif ($allChoicesAreEnums) { + $allChoicesAreEnums = true; + } + + if ($allChoicesAreEnums) { $processedEnumChoices = []; foreach ($choices as $choice) { - if ($choice instanceof \BackedEnum) { - $processedEnumChoices[$choice->name] = $choice->value; - } else { - $processedEnumChoices[$choice->name] = $choice->name; - } + $processedEnumChoices[$choice->name] = $choice; } $choices = $processedEnumChoices; diff --git a/tests/Field/Configurator/ChoiceConfiguratorTest.php b/tests/Field/Configurator/ChoiceConfiguratorTest.php index 57cb832ea0..889413a0f7 100644 --- a/tests/Field/Configurator/ChoiceConfiguratorTest.php +++ b/tests/Field/Configurator/ChoiceConfiguratorTest.php @@ -51,7 +51,12 @@ public function testBackedEnumTypeChoices(): void $field = ChoiceField::new(self::PROPERTY_NAME); $field->getAsDto()->setDoctrineMetadata(['enumType' => StatusBackedEnum::class]); - $this->assertSame($this->configure($field)->getFormTypeOption('choices'), StatusBackedEnum::cases()); + $formChoices = array_combine( + array_column(StatusBackedEnum::cases(), 'name'), + StatusBackedEnum::cases(), + ); + + $this->assertSame($this->configure($field)->getFormTypeOption('choices'), $formChoices); } public function testBackedEnumChoices(): void @@ -63,7 +68,7 @@ public function testBackedEnumChoices(): void $expected = []; foreach (StatusBackedEnum::cases() as $case) { - $expected[$case->name] = $case->value; + $expected[$case->name] = $case; } $this->assertSame($this->configure($field)->getFormTypeOption('choices'), $expected); @@ -76,7 +81,12 @@ public function testUnitEnumTypeChoices(): void $field = ChoiceField::new(self::PROPERTY_NAME); $field->getAsDto()->setDoctrineMetadata(['enumType' => PriorityUnitEnum::class]); - $this->assertSame($this->configure($field)->getFormTypeOption('choices'), PriorityUnitEnum::cases()); + $formChoices = array_combine( + array_column(PriorityUnitEnum::cases(), 'name'), + PriorityUnitEnum::cases(), + ); + + $this->assertSame($this->configure($field)->getFormTypeOption('choices'), $formChoices); } public function testUnitEnumChoices(): void @@ -88,7 +98,7 @@ public function testUnitEnumChoices(): void $expected = []; foreach (PriorityUnitEnum::cases() as $case) { - $expected[$case->name] = $case->name; + $expected[$case->name] = $case; } $this->assertSame($this->configure($field)->getFormTypeOption('choices'), $expected);