Skip to content

Commit

Permalink
IBX-7935: Refactored default value for the struct option
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed May 10, 2024
1 parent 9d790b3 commit 2a493e7
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/lib/Form/Type/Content/BaseContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,31 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setRequired(['languageCode', 'mainLanguageCode', 'struct'])
->setDefault('struct', static function (Options $options, $value) {
if ($value !== null) {
return $value;
}

return $options['userUpdateStruct']
?? $options['userCreateStruct']
?? $options['contentUpdateStruct']
?? $options['contentCreateStruct']
?? null;
})
->setDefaults([
'translation_domain' => 'ibexa_content_forms_content',
'contentCreateStruct' => null,
'contentUpdateStruct' => null,
'struct' => null,
])
->setAllowedTypes(
'struct',
[
'null',
ContentCreateStruct::class,
ContentUpdateStruct::class,
UserCreateStruct::class,
UserUpdateStruct::class,
],
)
->addNormalizer('struct', static function (Options $options, $value) {
if ($value !== null) {
return $value;
}

if (isset($options['userUpdateStruct'])
xor isset($options['userCreateStruct'])
xor isset($options['contentUpdateStruct'])
xor isset($options['contentCreateStruct'])
) {
return $options['userUpdateStruct']
?? $options['userCreateStruct']
?? $options['contentUpdateStruct']
?? $options['contentCreateStruct']
;
}

return null;
}, true)
->setDeprecated(
'contentCreateStruct',
'ibexa/content-forms',
Expand Down

0 comments on commit 2a493e7

Please sign in to comment.