Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-7935: Allowed null value for struct in user Types #70

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/lib/Form/Type/Content/BaseContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,9 +73,7 @@ public function configureOptions(OptionsResolver $resolver)
return $value;
}

return $options['userUpdateStruct']
?? $options['userCreateStruct']
?? $options['contentUpdateStruct']
return $options['contentUpdateStruct']
Steveb-p marked this conversation as resolved.
Show resolved Hide resolved
?? $options['contentCreateStruct']
?? null;
})
Expand All @@ -91,8 +88,6 @@ public function configureOptions(OptionsResolver $resolver)
'null',
ContentCreateStruct::class,
ContentUpdateStruct::class,
UserCreateStruct::class,
UserUpdateStruct::class,
],
)
->setDeprecated(
Expand All @@ -106,6 +101,20 @@ 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;
}
Steveb-p marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/Form/Type/User/UserCreateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/lib/Form/Type/User/UserUpdateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setRequired('struct')
->setDefaults([
'location' => null,
'content' => null,
'data_class' => UserUpdateData::class,
'intent' => 'update',
'translation_domain' => 'ibexa_content_forms_user',
])
->setAllowedTypes('struct', UserUpdateStruct::class);
->setAllowedTypes('struct', ['null', UserUpdateStruct::class]);
}
}

Expand Down
Loading