From bf48cfe92392c247821e4e6ae4e092301a809903 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Tue, 25 Jun 2024 14:23:41 +0200 Subject: [PATCH 1/3] IBX-7935: Allowed null value for struct in user Types --- src/lib/Form/Type/Content/BaseContentType.php | 19 ++++++++++++++----- src/lib/Form/Type/User/UserCreateType.php | 3 +-- src/lib/Form/Type/User/UserUpdateType.php | 3 +-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index 515f848..aeeacdc 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -74,9 +74,7 @@ public function configureOptions(OptionsResolver $resolver) return $value; } - return $options['userUpdateStruct'] - ?? $options['userCreateStruct'] - ?? $options['contentUpdateStruct'] + return $options['contentUpdateStruct'] ?? $options['contentCreateStruct'] ?? null; }) @@ -91,8 +89,6 @@ public function configureOptions(OptionsResolver $resolver) 'null', ContentCreateStruct::class, ContentUpdateStruct::class, - UserCreateStruct::class, - UserUpdateStruct::class, ], ) ->setDeprecated( @@ -106,6 +102,19 @@ public function configureOptions(OptionsResolver $resolver) 'ibexa/content-forms', 'v4.6.4', 'The option "%name%" is deprecated, use "struct" instead.' + ) + ->setNormalizer('struct', + static function (Options $options, ?UserCreateStruct $value): ?UserCreateStruct { + if ($value === null) { + trigger_deprecation( + 'ibexa/content-forms', + 'v4.6', + 'The option "struct" with null value is deprecated and will be required in v5.0.' + ); + } + + return $value; + } ); } } diff --git a/src/lib/Form/Type/User/UserCreateType.php b/src/lib/Form/Type/User/UserCreateType.php index 2fd75bc..688fe1a 100644 --- a/src/lib/Form/Type/User/UserCreateType.php +++ b/src/lib/Form/Type/User/UserCreateType.php @@ -47,13 +47,12 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver): void { $resolver - ->setRequired('struct') ->setDefaults([ 'data_class' => UserCreateData::class, 'intent' => 'create', 'translation_domain' => 'ibexa_content_forms_user', ]) - ->setAllowedTypes('struct', UserCreateStruct::class); + ->setAllowedTypes('struct', ['null', UserCreateStruct::class]); } } diff --git a/src/lib/Form/Type/User/UserUpdateType.php b/src/lib/Form/Type/User/UserUpdateType.php index 3fcd4cf..c63804e 100644 --- a/src/lib/Form/Type/User/UserUpdateType.php +++ b/src/lib/Form/Type/User/UserUpdateType.php @@ -47,7 +47,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver): void { $resolver - ->setRequired('struct') ->setDefaults([ 'location' => null, 'content' => null, @@ -55,7 +54,7 @@ public function configureOptions(OptionsResolver $resolver): void 'intent' => 'update', 'translation_domain' => 'ibexa_content_forms_user', ]) - ->setAllowedTypes('struct', UserUpdateStruct::class); + ->setAllowedTypes('struct', ['null', UserUpdateStruct::class]); } } From 103b2c0b6eb815359c49233d3885a3a580997398 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Tue, 25 Jun 2024 14:31:18 +0200 Subject: [PATCH 2/3] Fixed typehints --- src/lib/Form/Type/Content/BaseContentType.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index aeeacdc..9dd6242 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -9,9 +9,8 @@ namespace Ibexa\ContentForms\Form\Type\Content; use Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct; +use Ibexa\Contracts\Core\Repository\Values\Content\ContentStruct; use Ibexa\Contracts\Core\Repository\Values\Content\ContentUpdateStruct; -use Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct; -use Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct; use JMS\TranslationBundle\Annotation\Desc; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; @@ -103,8 +102,9 @@ public function configureOptions(OptionsResolver $resolver) 'v4.6.4', 'The option "%name%" is deprecated, use "struct" instead.' ) - ->setNormalizer('struct', - static function (Options $options, ?UserCreateStruct $value): ?UserCreateStruct { + ->setNormalizer( + 'struct', + static function (Options $options, ?ContentStruct $value): ?ContentStruct { if ($value === null) { trigger_deprecation( 'ibexa/content-forms', From 5ebb8a85681d29d1ae8457847b10008c8bdb809c Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Wed, 10 Jul 2024 08:54:22 +0200 Subject: [PATCH 3/3] Moved deprecation to default options callback --- src/lib/Form/Type/Content/BaseContentType.php | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index 9dd6242..84c5a01 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -68,11 +68,17 @@ public function configureOptions(OptionsResolver $resolver) { $resolver ->setRequired(['languageCode', 'mainLanguageCode', 'struct']) - ->setDefault('struct', static function (Options $options, $value) { + ->setDefault('struct', static function (Options $options, ?ContentStruct $value) { if ($value !== null) { return $value; } + trigger_deprecation( + 'ibexa/content-forms', + 'v4.6', + 'The option "struct" with null value is deprecated and will be required in v5.0.' + ); + return $options['contentUpdateStruct'] ?? $options['contentCreateStruct'] ?? null; @@ -101,20 +107,6 @@ public function configureOptions(OptionsResolver $resolver) 'ibexa/content-forms', 'v4.6.4', 'The option "%name%" is deprecated, use "struct" instead.' - ) - ->setNormalizer( - 'struct', - static function (Options $options, ?ContentStruct $value): ?ContentStruct { - if ($value === null) { - trigger_deprecation( - 'ibexa/content-forms', - 'v4.6', - 'The option "struct" with null value is deprecated and will be required in v5.0.' - ); - } - - return $value; - } ); } }