Skip to content

Commit

Permalink
IBX-7935: Allowed null value for struct in user Types
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Jun 25, 2024
1 parent 04dd868 commit bf48cfe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
19 changes: 14 additions & 5 deletions src/lib/Form/Type/Content/BaseContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public function configureOptions(OptionsResolver $resolver)
return $value;
}

return $options['userUpdateStruct']
?? $options['userCreateStruct']
?? $options['contentUpdateStruct']
return $options['contentUpdateStruct']
?? $options['contentCreateStruct']
?? null;
})
Expand All @@ -91,8 +89,6 @@ public function configureOptions(OptionsResolver $resolver)
'null',
ContentCreateStruct::class,
ContentUpdateStruct::class,
UserCreateStruct::class,
UserUpdateStruct::class,
],
)
->setDeprecated(
Expand All @@ -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;
}
);
}
}
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

0 comments on commit bf48cfe

Please sign in to comment.