From 1de5d605956f40d142af55e3e688058089d9d145 Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Fri, 17 Feb 2023 21:48:41 +0200 Subject: [PATCH 01/10] Update ChoiceConfigurator.php --- src/Field/Configurator/ChoiceConfigurator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Field/Configurator/ChoiceConfigurator.php b/src/Field/Configurator/ChoiceConfigurator.php index 104b5a4ace..7438bb21b3 100644 --- a/src/Field/Configurator/ChoiceConfigurator.php +++ b/src/Field/Configurator/ChoiceConfigurator.php @@ -49,6 +49,8 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c // support for enums if ($enumsAreSupported) { + $field->setFormType(EnumType::class); + $elementIsEnum = array_unique(array_map(static function ($element): bool { return \is_object($element) && enum_exists($element::class); }, $choices)); From 668637d4dc163765c859e320e54fcec33f5434cb Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Fri, 17 Feb 2023 21:49:26 +0200 Subject: [PATCH 02/10] Update FieldFactory.php --- src/Factory/FieldFactory.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Factory/FieldFactory.php b/src/Factory/FieldFactory.php index a081ee2cda..c8edc89f8e 100644 --- a/src/Factory/FieldFactory.php +++ b/src/Factory/FieldFactory.php @@ -99,6 +99,12 @@ public function processFields(EntityDto $entityDto, FieldCollection $fields): vo $configurator->configure($fieldDto, $entityDto, $context); } + + if (null !== $currentPage && false === $fieldDto->isDisplayedOn($currentPage)) { + $fields->unset($fieldDto); + + continue; + } foreach ($fieldDto->getFormThemes() as $formThemePath) { $context?->getCrud()?->addFormTheme($formThemePath); From 2b5ae73a91d5d567c0efce8da960c91e8a39df53 Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Sat, 18 Feb 2023 10:55:52 +0200 Subject: [PATCH 03/10] Update ChoiceConfigurator.php --- src/Field/Configurator/ChoiceConfigurator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Field/Configurator/ChoiceConfigurator.php b/src/Field/Configurator/ChoiceConfigurator.php index 7438bb21b3..9fcdb17494 100644 --- a/src/Field/Configurator/ChoiceConfigurator.php +++ b/src/Field/Configurator/ChoiceConfigurator.php @@ -10,6 +10,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField; use EasyCorp\Bundle\EasyAdminBundle\Translation\TranslatableChoiceMessage; use EasyCorp\Bundle\EasyAdminBundle\Translation\TranslatableChoiceMessageCollection; +use Symfony\Component\Form\Extension\Core\Type\EnumType; use function Symfony\Component\String\u; use function Symfony\Component\Translation\t; use Symfony\Contracts\Translation\TranslatableInterface; From aaf188f3040aa315b59524357322b2e44f5c1f52 Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Sat, 18 Feb 2023 13:28:12 +0200 Subject: [PATCH 04/10] Update ChoiceConfigurator.php --- src/Field/Configurator/ChoiceConfigurator.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Field/Configurator/ChoiceConfigurator.php b/src/Field/Configurator/ChoiceConfigurator.php index 9fcdb17494..2ab78c4b3e 100644 --- a/src/Field/Configurator/ChoiceConfigurator.php +++ b/src/Field/Configurator/ChoiceConfigurator.php @@ -40,6 +40,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c if (null === $choices && $enumsAreSupported) { $enumTypeClass = $field->getDoctrineMetadata()->get('enumType'); if (enum_exists($enumTypeClass)) { + $field->setFormTypeOption('class', $enumTypeClass); $choices = $enumTypeClass::cases(); } } @@ -49,22 +50,18 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c } // support for enums - if ($enumsAreSupported) { - $field->setFormType(EnumType::class); - + if ($enumsAreSupported) { $elementIsEnum = array_unique(array_map(static function ($element): bool { return \is_object($element) && enum_exists($element::class); }, $choices)); $allChoicesAreEnums = false === \in_array(false, $elementIsEnum, true); if ($allChoicesAreEnums) { + $field->setFormType(EnumType::class); + $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; From 0b56135b5655bf053f5dad8560017bca5f7b7e66 Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Sat, 18 Feb 2023 15:24:12 +0200 Subject: [PATCH 05/10] Update ChoiceConfigurator.php --- src/Field/Configurator/ChoiceConfigurator.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Field/Configurator/ChoiceConfigurator.php b/src/Field/Configurator/ChoiceConfigurator.php index 2ab78c4b3e..9b9efe61bf 100644 --- a/src/Field/Configurator/ChoiceConfigurator.php +++ b/src/Field/Configurator/ChoiceConfigurator.php @@ -114,6 +114,13 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c if ($selectedValue instanceof TranslatableInterface) { $choiceMessage = $selectedValue; } else { + if (\is_object($selectedLabel)) { + $labeLCallback = $field->getFormTypeOption('choice_label'); + if (\is_callable($labeLCallback)) { + $selectedLabel = $labeLCallback($selectedLabel); + } + } + $choiceMessage = t( $selectedLabel, $translationParameters, From 623e556788740f173e1443727faf1ae35581f6d5 Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Sat, 18 Feb 2023 15:28:27 +0200 Subject: [PATCH 06/10] Update ChoiceConfigurator.php --- src/Field/Configurator/ChoiceConfigurator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Field/Configurator/ChoiceConfigurator.php b/src/Field/Configurator/ChoiceConfigurator.php index 9b9efe61bf..059783e581 100644 --- a/src/Field/Configurator/ChoiceConfigurator.php +++ b/src/Field/Configurator/ChoiceConfigurator.php @@ -50,7 +50,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c } // support for enums - if ($enumsAreSupported) { + if ($enumsAreSupported) { $elementIsEnum = array_unique(array_map(static function ($element): bool { return \is_object($element) && enum_exists($element::class); }, $choices)); From a8ef095cb81001de0736449f0d91758dfd20dbce Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Sat, 18 Feb 2023 16:45:47 +0200 Subject: [PATCH 07/10] Update ChoiceConfigurator.php --- src/Field/Configurator/ChoiceConfigurator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Field/Configurator/ChoiceConfigurator.php b/src/Field/Configurator/ChoiceConfigurator.php index 059783e581..ad18f489df 100644 --- a/src/Field/Configurator/ChoiceConfigurator.php +++ b/src/Field/Configurator/ChoiceConfigurator.php @@ -39,7 +39,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c // in that case, get all the possible values of the Enum if (null === $choices && $enumsAreSupported) { $enumTypeClass = $field->getDoctrineMetadata()->get('enumType'); - if (enum_exists($enumTypeClass)) { + if ($enumTypeClass && enum_exists($enumTypeClass)) { $field->setFormTypeOption('class', $enumTypeClass); $choices = $enumTypeClass::cases(); } From e6002af278358e3e774ecb35ee84322bddd822d2 Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Tue, 21 Feb 2023 17:16:53 +0200 Subject: [PATCH 08/10] Update Actions.php --- src/Config/Actions.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Config/Actions.php b/src/Config/Actions.php index 758b5cd766..9c0329e0a8 100644 --- a/src/Config/Actions.php +++ b/src/Config/Actions.php @@ -241,4 +241,9 @@ private function doAddAction(string $pageName, Action|string $actionNameOrObject return $this; } + + public function __clone() + { + $this->dto = clone $this->dto; + } } From 5b5f069b8b8bf87d9d6c1c969bd4b63297eb1540 Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Tue, 21 Feb 2023 17:48:13 +0200 Subject: [PATCH 09/10] Update Actions.php --- src/Config/Actions.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Config/Actions.php b/src/Config/Actions.php index 9c0329e0a8..758b5cd766 100644 --- a/src/Config/Actions.php +++ b/src/Config/Actions.php @@ -241,9 +241,4 @@ private function doAddAction(string $pageName, Action|string $actionNameOrObject return $this; } - - public function __clone() - { - $this->dto = clone $this->dto; - } } From 19abafc4b4f73092b3c1ebf3c29f720ed8bea3de Mon Sep 17 00:00:00 2001 From: Alexandar Bozhinov Date: Sun, 12 Mar 2023 15:38:12 +0200 Subject: [PATCH 10/10] Update ChoiceConfigurator.php --- src/Field/Configurator/ChoiceConfigurator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Field/Configurator/ChoiceConfigurator.php b/src/Field/Configurator/ChoiceConfigurator.php index ad18f489df..d42040780c 100644 --- a/src/Field/Configurator/ChoiceConfigurator.php +++ b/src/Field/Configurator/ChoiceConfigurator.php @@ -39,7 +39,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c // in that case, get all the possible values of the Enum if (null === $choices && $enumsAreSupported) { $enumTypeClass = $field->getDoctrineMetadata()->get('enumType'); - if ($enumTypeClass && enum_exists($enumTypeClass)) { + if (is_string($enumTypeClass) && enum_exists($enumTypeClass)) { $field->setFormTypeOption('class', $enumTypeClass); $choices = $enumTypeClass::cases(); }