Skip to content

Commit

Permalink
IBX-7935: Applied review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed May 10, 2024
1 parent b4e534a commit adb6887
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/bundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function createAction(
$form = $this->createForm(UserCreateType::class, $data, [
'languageCode' => $language->languageCode,
'mainLanguageCode' => $language->languageCode,
'userCreateStruct' => $data,
'struct' => $data,
]);
$form->handleRequest($request);

Expand Down Expand Up @@ -203,8 +203,8 @@ public function editAction(
'content' => $this->contentService->loadContent($contentId),
'languageCode' => $language,
'mainLanguageCode' => $user->contentInfo->mainLanguageCode,
'userUpdateStruct' => $userUpdate,
]
'struct' => $userUpdate,
],
);
$form->handleRequest($request);

Expand Down
41 changes: 34 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,9 @@
namespace Ibexa\ContentForms\Form\Type\Content;

use Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct;
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 Ibexa\Core\Repository\Values\Content\ContentUpdateStruct;
use JMS\TranslationBundle\Annotation\Desc;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
Expand Down Expand Up @@ -47,8 +47,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'mainLanguageCode' => $options['mainLanguageCode'],
'location' => $options['location'] ?? null,
'content' => $options['content'] ?? null,
'contentCreateStruct' => $options['contentCreateStruct'] ?? null, // deprecated
'contentUpdateStruct' => $options['contentUpdateStruct'] ?? null, // deprecated
'contentCreateStruct' => $options['contentCreateStruct'] ?? null,
'contentUpdateStruct' => $options['contentUpdateStruct'] ?? null,
'struct' => $options['struct'],
],
])
Expand All @@ -70,6 +70,8 @@ public function configureOptions(OptionsResolver $resolver)
->setDefaults([
'translation_domain' => 'ibexa_content_forms_content',
'struct' => null,
'contentCreateStruct' => null,
'contentUpdateStruct' => null,
])
->setAllowedTypes(
'struct',
Expand All @@ -83,11 +85,36 @@ public function configureOptions(OptionsResolver $resolver)
)
->setRequired(['languageCode', 'mainLanguageCode', 'struct'])
->setNormalizer('struct', static function (Options $options, $value) {
return $options['userUpdateStruct']
?? $options['userCreateStruct']
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'];
});
?? $options['contentCreateStruct']
;
}

return null;
})
->setDeprecated(
'contentCreateStruct',
'ibexa/content-forms',
'v4.6.4',
'The option "%name%" is deprecated, use "struct" instead.'
)
->setDeprecated(
'contentUpdateStruct',
'ibexa/content-forms',
'v4.6.4',
'The option "%name%" is deprecated, use "struct" instead.'
);
}
}

Expand Down
34 changes: 31 additions & 3 deletions src/lib/Form/Type/Content/ContentFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

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\ContentUpdateStruct;
use Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct;
use Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
Expand Down Expand Up @@ -46,13 +50,37 @@ public function configureOptions(OptionsResolver $resolver)
->setDefaults([
'content' => null,
'location' => null,
'contentCreateStruct' => null, // deprecated
'contentUpdateStruct' => null, // deprecated
'contentCreateStruct' => null,
'contentUpdateStruct' => null,
'data_class' => FieldData::class,
'translation_domain' => 'ibexa_content_forms_content',
'struct' => null,
])
->setRequired(['languageCode', 'mainLanguageCode', 'struct']);
->setAllowedTypes(
'struct',
[
'null',
ContentCreateStruct::class,
ContentUpdateStruct::class,
UserCreateStruct::class,
UserUpdateStruct::class,
],
)
->setAllowedTypes('contentCreateStruct', ['null', ContentCreateStruct::class])
->setAllowedTypes('contentUpdateStruct', ['null', ContentUpdateStruct::class])
->setRequired(['languageCode', 'mainLanguageCode', 'struct'])
->setDeprecated(
'contentCreateStruct',
'ibexa/content-forms',
'v4.6.4',
'The option "%name%" is deprecated, use "struct" instead.'
)
->setDeprecated(
'contentUpdateStruct',
'ibexa/content-forms',
'v4.6.4',
'The option "%name%" is deprecated, use "struct" instead.'
);
}

public function buildView(FormView $view, FormInterface $form, array $options)
Expand Down
1 change: 0 additions & 1 deletion src/lib/Form/Type/Content/FieldCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private function dispatchFieldOptionsEvent(
array $entryOptions,
FormInterface $form
): array {
dump($entryOptions);
if ($this->isContentUpdate($entryOptions)) {
/** @var \Ibexa\ContentForms\Event\ContentUpdateFieldOptionsEvent $contentUpdateFieldOptionsEvent */
$contentUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch(
Expand Down
6 changes: 4 additions & 2 deletions src/lib/Form/Type/User/UserCreateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Ibexa\ContentForms\Form\Type\User;

use Ibexa\ContentForms\Data\User\UserCreateData;
use Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct;
use JMS\TranslationBundle\Annotation\Desc;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
Expand Down Expand Up @@ -47,11 +48,12 @@ public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefaults([
'userCreateStruct' => null,
'struct' => null,
'data_class' => UserCreateData::class,
'intent' => 'create',
'translation_domain' => 'ibexa_content_forms_user',
]);
])
->setAllowedTypes('struct', UserCreateStruct::class);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib/Form/Type/User/UserUpdateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Ibexa\ContentForms\Form\Type\User;

use Ibexa\ContentForms\Data\User\UserUpdateData;
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\SubmitType;
Expand Down Expand Up @@ -49,11 +50,12 @@ public function configureOptions(OptionsResolver $resolver): void
->setDefaults([
'location' => null,
'content' => null,
'userUpdateStruct' => null,
'struct' => null,
'data_class' => UserUpdateData::class,
'intent' => 'update',
'translation_domain' => 'ibexa_content_forms_user',
]);
])
->setAllowedTypes('struct', UserUpdateStruct::class);
}
}

Expand Down

0 comments on commit adb6887

Please sign in to comment.