From 7a0287e167874f3da9eab4277731bcbef889fed6 Mon Sep 17 00:00:00 2001 From: pawelpawlik Date: Tue, 1 Oct 2024 10:08:44 +0200 Subject: [PATCH] IBX-8711 added setting default for struct option in ContentFieldType --- src/lib/Form/Type/Content/ContentFieldType.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib/Form/Type/Content/ContentFieldType.php b/src/lib/Form/Type/Content/ContentFieldType.php index 71b52b0..23cfd66 100644 --- a/src/lib/Form/Type/Content/ContentFieldType.php +++ b/src/lib/Form/Type/Content/ContentFieldType.php @@ -11,6 +11,7 @@ use Ibexa\ContentForms\FieldType\FieldTypeFormMapperDispatcherInterface; use Ibexa\Contracts\ContentForms\Data\Content\FieldData; 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; @@ -20,6 +21,7 @@ use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; +use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; class ContentFieldType extends AbstractType @@ -48,6 +50,21 @@ public function configureOptions(OptionsResolver $resolver) { $resolver ->setRequired(['languageCode', 'mainLanguageCode', 'struct']) + ->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; + }) ->setDefaults([ 'content' => null, 'location' => null,