From 72fd718e643e4069ba117c690216a31a44972622 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Thu, 14 Mar 2024 16:50:23 +0100 Subject: [PATCH 01/17] IBX-7935: Handled User-related structs in `FieldCollectionType` dispatcher --- src/bundle/Controller/UserController.php | 12 +- src/bundle/Resources/config/services.yaml | 17 +-- src/lib/Event/ContentFormEvents.php | 10 ++ src/lib/Event/UserCreateFieldOptionsEvent.php | 82 ++++++++++++ src/lib/Event/UserUpdateFieldOptionsEvent.php | 98 ++++++++++++++ src/lib/Form/Type/Content/BaseContentType.php | 2 + .../Form/Type/Content/ContentFieldType.php | 2 + .../Form/Type/Content/FieldCollectionType.php | 123 +++++++++++++----- src/lib/Form/Type/User/UserCreateType.php | 3 +- src/lib/Form/Type/User/UserUpdateType.php | 4 +- 10 files changed, 311 insertions(+), 42 deletions(-) create mode 100644 src/lib/Event/UserCreateFieldOptionsEvent.php create mode 100644 src/lib/Event/UserUpdateFieldOptionsEvent.php diff --git a/src/bundle/Controller/UserController.php b/src/bundle/Controller/UserController.php index 1f94138e..d68ef09d 100644 --- a/src/bundle/Controller/UserController.php +++ b/src/bundle/Controller/UserController.php @@ -17,6 +17,7 @@ use Ibexa\ContentForms\User\View\UserCreateView; use Ibexa\ContentForms\User\View\UserUpdateView; use Ibexa\Contracts\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProviderInterface; +use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\ContentTypeService; use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException; use Ibexa\Contracts\Core\Repository\LanguageService; @@ -53,6 +54,9 @@ class UserController extends Controller /** @var \Ibexa\Contracts\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProviderInterface */ private $groupedContentFormFieldsProvider; + /** @var \Ibexa\Contracts\Core\Repository\ContentService */ + private $contentService; + public function __construct( ContentTypeService $contentTypeService, UserService $userService, @@ -61,7 +65,8 @@ public function __construct( ActionDispatcherInterface $userActionDispatcher, PermissionResolver $permissionResolver, UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider, - GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider + GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider, + ContentService $contentService ) { $this->contentTypeService = $contentTypeService; $this->userService = $userService; @@ -71,6 +76,7 @@ public function __construct( $this->permissionResolver = $permissionResolver; $this->userLanguagePreferenceProvider = $userLanguagePreferenceProvider; $this->groupedContentFormFieldsProvider = $groupedContentFormFieldsProvider; + $this->contentService = $contentService; } /** @@ -114,6 +120,7 @@ public function createAction( $form = $this->createForm(UserCreateType::class, $data, [ 'languageCode' => $language->languageCode, 'mainLanguageCode' => $language->languageCode, + 'userCreateStruct' => $data, ]); $form->handleRequest($request); @@ -152,6 +159,7 @@ public function createAction( * @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType * @throws \Ibexa\Core\Base\Exceptions\UnauthorizedException */ @@ -192,8 +200,10 @@ public function editAction( $userUpdate, [ 'location' => $location, + 'content' => $this->contentService->loadContent($contentId), 'languageCode' => $language, 'mainLanguageCode' => $user->contentInfo->mainLanguageCode, + 'userUpdateStruct' => $userUpdate, ] ); $form->handleRequest($request); diff --git a/src/bundle/Resources/config/services.yaml b/src/bundle/Resources/config/services.yaml index eed59f8b..2d9f0621 100644 --- a/src/bundle/Resources/config/services.yaml +++ b/src/bundle/Resources/config/services.yaml @@ -99,14 +99,15 @@ services: Ibexa\Bundle\ContentForms\Controller\UserController: arguments: - - '@ibexa.api.service.content_type' - - '@ibexa.api.service.user' - - '@ibexa.api.service.location' - - '@ibexa.api.service.language' - - '@Ibexa\ContentForms\Form\ActionDispatcher\UserDispatcher' - - '@Ibexa\Contracts\Core\Repository\PermissionResolver' - - '@Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProvider' - - '@Ibexa\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProvider' + $contentTypeService: '@ibexa.api.service.content_type' + $userService: '@ibexa.api.service.user' + $locationService: '@ibexa.api.service.location' + $languageService: '@ibexa.api.service.language' + $userActionDispatcher: '@Ibexa\ContentForms\Form\ActionDispatcher\UserDispatcher' + $permissionResolver: '@Ibexa\Contracts\Core\Repository\PermissionResolver' + $userLanguagePreferenceProvider: '@Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProvider' + $groupedContentFormFieldsProvider: '@Ibexa\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProvider' + $contentService: '@ibexa.api.service.content' parent: Ibexa\Core\MVC\Symfony\Controller\Controller tags: - { name: controller.service_arguments } diff --git a/src/lib/Event/ContentFormEvents.php b/src/lib/Event/ContentFormEvents.php index 62226a2a..9f2de30f 100644 --- a/src/lib/Event/ContentFormEvents.php +++ b/src/lib/Event/ContentFormEvents.php @@ -74,6 +74,16 @@ final class ContentFormEvents * Triggered when resolving Field Type options for content create form. */ public const CONTENT_CREATE_FIELD_OPTIONS = 'content.create.field.options'; + + /** + * Triggered when resolving Field Type options for user edit form. + */ + public const USER_EDIT_FIELD_OPTIONS = 'user.edit.field.options'; + + /** + * Triggered when resolving Field Type options for user create form. + */ + public const USER_CREATE_FIELD_OPTIONS = 'user.create.field.options'; } class_alias(ContentFormEvents::class, 'EzSystems\EzPlatformContentForms\Event\ContentFormEvents'); diff --git a/src/lib/Event/UserCreateFieldOptionsEvent.php b/src/lib/Event/UserCreateFieldOptionsEvent.php new file mode 100644 index 00000000..26a05e84 --- /dev/null +++ b/src/lib/Event/UserCreateFieldOptionsEvent.php @@ -0,0 +1,82 @@ + */ + private $options; + + public function __construct( + UserCreateStruct $userCreateStruct, + FormInterface $parentForm, + FieldData $fieldData, + array $options + ) { + $this->userCreateStruct = $userCreateStruct; + $this->parentForm = $parentForm; + $this->fieldData = $fieldData; + $this->options = $options; + } + + public function getUserCreateStruct(): UserCreateStruct + { + return $this->userCreateStruct; + } + + public function getParentForm(): FormInterface + { + return $this->parentForm; + } + + public function getFieldData(): FieldData + { + return $this->fieldData; + } + + /** + * @return array + */ + public function getOptions(): array + { + return $this->options; + } + + /** + * @param array $options + */ + public function setOptions(array $options): void + { + $this->options = $options; + } + + public function setOption(string $option, $value): void + { + $this->options[$option] = $value; + } + + public function getOption(string $option) + { + return $this->options[$option] ?? null; + } +} diff --git a/src/lib/Event/UserUpdateFieldOptionsEvent.php b/src/lib/Event/UserUpdateFieldOptionsEvent.php new file mode 100644 index 00000000..6c2a62c4 --- /dev/null +++ b/src/lib/Event/UserUpdateFieldOptionsEvent.php @@ -0,0 +1,98 @@ + */ + private $options; + + public function __construct( + Content $content, + UserUpdateStruct $userUpdateStruct, + FormInterface $parentForm, + FieldData $fieldData, + array $options + ) { + $this->content = $content; + $this->userUpdateStruct = $userUpdateStruct; + $this->parentForm = $parentForm; + $this->fieldData = $fieldData; + $this->options = $options; + } + + public function getContent(): Content + { + return $this->content; + } + + public function setContent(Content $content): void + { + $this->content = $content; + } + + public function getUserUpdateStruct(): UserUpdateStruct + { + return $this->userUpdateStruct; + } + + public function getParentForm(): FormInterface + { + return $this->parentForm; + } + + public function getFieldData(): FieldData + { + return $this->fieldData; + } + + /** + * @return array + */ + public function getOptions(): array + { + return $this->options; + } + + /** + * @param array $options + */ + public function setOptions(array $options): void + { + $this->options = $options; + } + + public function setOption(string $option, $value): void + { + $this->options[$option] = $value; + } + + public function getOption(string $option) + { + return $this->options[$option] ?? null; + } +} diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index cf2fdfce..51ec4161 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -44,6 +44,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'content' => $options['content'] ?? null, 'contentCreateStruct' => $options['contentCreateStruct'] ?? null, 'contentUpdateStruct' => $options['contentUpdateStruct'] ?? null, + 'userCreateStruct' => $options['userCreateStruct'] ?? null, + 'userUpdateStruct' => $options['userUpdateStruct'] ?? null, ], ]) ->add('redirectUrlAfterPublish', HiddenType::class, [ diff --git a/src/lib/Form/Type/Content/ContentFieldType.php b/src/lib/Form/Type/Content/ContentFieldType.php index b4a17f3e..78ce734a 100644 --- a/src/lib/Form/Type/Content/ContentFieldType.php +++ b/src/lib/Form/Type/Content/ContentFieldType.php @@ -48,6 +48,8 @@ public function configureOptions(OptionsResolver $resolver) 'location' => null, 'contentCreateStruct' => null, 'contentUpdateStruct' => null, + 'userCreateStruct' => null, + 'userUpdateStruct' => null, 'data_class' => FieldData::class, 'translation_domain' => 'ibexa_content_forms_content', ]) diff --git a/src/lib/Form/Type/Content/FieldCollectionType.php b/src/lib/Form/Type/Content/FieldCollectionType.php index 4873364b..39e9c32c 100644 --- a/src/lib/Form/Type/Content/FieldCollectionType.php +++ b/src/lib/Form/Type/Content/FieldCollectionType.php @@ -11,10 +11,14 @@ use Ibexa\ContentForms\Event\ContentCreateFieldOptionsEvent; use Ibexa\ContentForms\Event\ContentFormEvents; use Ibexa\ContentForms\Event\ContentUpdateFieldOptionsEvent; +use Ibexa\ContentForms\Event\UserCreateFieldOptionsEvent; +use Ibexa\ContentForms\Event\UserUpdateFieldOptionsEvent; +use Ibexa\Contracts\ContentForms\Data\Content\FieldData; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; +use Symfony\Component\Form\FormInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class FieldCollectionType extends CollectionType @@ -43,40 +47,12 @@ public function buildForm( } // Then add all rows again in the correct order - foreach ($data as $name => $value) { + foreach ($data as $name => $entryData) { $entryOptions = array_replace([ 'property_path' => '[' . $name . ']', ], $options['entry_options']); - $entryData = $data[$name]; - - if ($this->isContentUpdate($entryOptions)) { - /** @var \Ibexa\ContentForms\Event\ContentUpdateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ - $contentUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch( - new ContentUpdateFieldOptionsEvent( - $entryOptions['content'], - $entryOptions['contentUpdateStruct'], - $form, - $entryData, - $entryOptions - ), - ContentFormEvents::CONTENT_EDIT_FIELD_OPTIONS - ); - - $entryOptions = $contentUpdateFieldOptionsEvent->getOptions(); - } elseif ($this->isContentCreate($entryOptions)) { - /** @var \Ibexa\ContentForms\Event\ContentCreateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ - $contentCreateFieldOptionsEvent = $this->eventDispatcher->dispatch( - new ContentCreateFieldOptionsEvent( - $entryOptions['contentCreateStruct'], - $form, - $entryData, - $entryOptions - ), - ContentFormEvents::CONTENT_CREATE_FIELD_OPTIONS - ); - - $entryOptions = $contentCreateFieldOptionsEvent->getOptions(); - } + + $entryOptions = $this->dispatchFieldOptionsEvent($entryData, $entryOptions, $form); $form->add($name, $options['entry_type'], $entryOptions); } @@ -92,6 +68,91 @@ private function isContentUpdate(array $entryOptions): bool { return !empty($entryOptions['content']) && !empty($entryOptions['contentUpdateStruct']); } + + /** + * @param array $entryOptions + */ + private function isUserCreate(array $entryOptions): bool + { + return !empty($entryOptions['userCreateStruct']); + } + + /** + * @param array $entryOptions + */ + private function isUserUpdate(array $entryOptions): bool + { + return !empty($entryOptions['userUpdateStruct']); + } + + /** + * @param array $entryOptions + * + * @return array $entryOptions + */ + private function dispatchFieldOptionsEvent( + FieldData $entryData, + array $entryOptions, + FormInterface $form + ): array { + if ($this->isContentUpdate($entryOptions)) { + /** @var \Ibexa\ContentForms\Event\ContentUpdateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ + $contentUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch( + new ContentUpdateFieldOptionsEvent( + $entryOptions['content'], + $entryOptions['contentUpdateStruct'], + $form, + $entryData, + $entryOptions + ), + ContentFormEvents::CONTENT_EDIT_FIELD_OPTIONS + ); + + $entryOptions = $contentUpdateFieldOptionsEvent->getOptions(); + } elseif ($this->isContentCreate($entryOptions)) { + /** @var \Ibexa\ContentForms\Event\ContentCreateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ + $contentCreateFieldOptionsEvent = $this->eventDispatcher->dispatch( + new ContentCreateFieldOptionsEvent( + $entryOptions['contentCreateStruct'], + $form, + $entryData, + $entryOptions + ), + ContentFormEvents::CONTENT_CREATE_FIELD_OPTIONS + ); + + $entryOptions = $contentCreateFieldOptionsEvent->getOptions(); + } elseif ($this->isUserCreate($entryOptions)) { + /** @var \Ibexa\ContentForms\Event\UserCreateFieldOptionsEvent $userCreateFieldOptionsEvent */ + $userCreateFieldOptionsEvent = $this->eventDispatcher->dispatch( + new UserCreateFieldOptionsEvent( + $entryOptions['userCreateStruct'], + $form, + $entryData, + $entryOptions + ), + ContentFormEvents::USER_CREATE_FIELD_OPTIONS + ); + + $entryOptions = $userCreateFieldOptionsEvent->getOptions(); + } elseif ($this->isUserUpdate($entryOptions)) { + /** @var \Ibexa\ContentForms\Event\UserUpdateFieldOptionsEvent $userUpdateFieldOptionsEvent */ + $userUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch( + new UserUpdateFieldOptionsEvent( + $entryOptions['content'], + $entryOptions['userUpdateStruct'], + $form, + $entryData, + $entryOptions + ), + ContentFormEvents::USER_EDIT_FIELD_OPTIONS + ); + + $entryOptions = $userUpdateFieldOptionsEvent->getOptions(); + } + + return $entryOptions; + } } class_alias(FieldCollectionType::class, 'EzSystems\EzPlatformContentForms\Form\Type\Content\FieldCollectionType'); diff --git a/src/lib/Form/Type/User/UserCreateType.php b/src/lib/Form/Type/User/UserCreateType.php index 3d9f8b44..d1adbc35 100644 --- a/src/lib/Form/Type/User/UserCreateType.php +++ b/src/lib/Form/Type/User/UserCreateType.php @@ -43,10 +43,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('create', SubmitType::class, ['label' => /** @Desc("Create") */ 'user.create']); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver ->setDefaults([ + 'userCreateStruct' => null, 'data_class' => UserCreateData::class, 'intent' => 'create', 'translation_domain' => 'ibexa_content_forms_user', diff --git a/src/lib/Form/Type/User/UserUpdateType.php b/src/lib/Form/Type/User/UserUpdateType.php index 5b3af50d..2d95dd6c 100644 --- a/src/lib/Form/Type/User/UserUpdateType.php +++ b/src/lib/Form/Type/User/UserUpdateType.php @@ -43,11 +43,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('update', SubmitType::class, ['label' => /** @Desc("Update") */ 'user.update']); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver ->setDefaults([ 'location' => null, + 'content' => null, + 'userUpdateStruct' => null, 'data_class' => UserUpdateData::class, 'intent' => 'update', 'translation_domain' => 'ibexa_content_forms_user', From 7534cbad20d2ba354fb37ab0f1fa38a5552e3364 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 15 Mar 2024 11:48:06 +0100 Subject: [PATCH 02/17] IBX-7935: Refactored code --- src/lib/Event/UserCreateFieldOptionsEvent.php | 53 +------------- src/lib/Event/UserStructFieldOptionsEvent.php | 71 +++++++++++++++++++ src/lib/Event/UserUpdateFieldOptionsEvent.php | 58 +-------------- 3 files changed, 77 insertions(+), 105 deletions(-) create mode 100644 src/lib/Event/UserStructFieldOptionsEvent.php diff --git a/src/lib/Event/UserCreateFieldOptionsEvent.php b/src/lib/Event/UserCreateFieldOptionsEvent.php index 26a05e84..7c3cb905 100644 --- a/src/lib/Event/UserCreateFieldOptionsEvent.php +++ b/src/lib/Event/UserCreateFieldOptionsEvent.php @@ -11,22 +11,12 @@ use Ibexa\Contracts\ContentForms\Data\Content\FieldData; use Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct; use Symfony\Component\Form\FormInterface; -use Symfony\Contracts\EventDispatcher\Event; -final class UserCreateFieldOptionsEvent extends Event +final class UserCreateFieldOptionsEvent extends UserStructFieldOptionsEvent { /** @var \Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct */ private $userCreateStruct; - /** @var \Symfony\Component\Form\FormInterface */ - private $parentForm; - - /** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */ - private $fieldData; - - /** @var array */ - private $options; - public function __construct( UserCreateStruct $userCreateStruct, FormInterface $parentForm, @@ -34,49 +24,12 @@ public function __construct( array $options ) { $this->userCreateStruct = $userCreateStruct; - $this->parentForm = $parentForm; - $this->fieldData = $fieldData; - $this->options = $options; + + parent::__construct($parentForm, $fieldData, $options); } public function getUserCreateStruct(): UserCreateStruct { return $this->userCreateStruct; } - - public function getParentForm(): FormInterface - { - return $this->parentForm; - } - - public function getFieldData(): FieldData - { - return $this->fieldData; - } - - /** - * @return array - */ - public function getOptions(): array - { - return $this->options; - } - - /** - * @param array $options - */ - public function setOptions(array $options): void - { - $this->options = $options; - } - - public function setOption(string $option, $value): void - { - $this->options[$option] = $value; - } - - public function getOption(string $option) - { - return $this->options[$option] ?? null; - } } diff --git a/src/lib/Event/UserStructFieldOptionsEvent.php b/src/lib/Event/UserStructFieldOptionsEvent.php new file mode 100644 index 00000000..541dd61a --- /dev/null +++ b/src/lib/Event/UserStructFieldOptionsEvent.php @@ -0,0 +1,71 @@ + */ + protected $options; + + public function __construct( + FormInterface $parentForm, + FieldData $fieldData, + array $options + ) { + $this->parentForm = $parentForm; + $this->fieldData = $fieldData; + $this->options = $options; + } + + public function getParentForm(): FormInterface + { + return $this->parentForm; + } + + public function getFieldData(): FieldData + { + return $this->fieldData; + } + + /** + * @return array + */ + public function getOptions(): array + { + return $this->options; + } + + /** + * @param array $options + */ + public function setOptions(array $options): void + { + $this->options = $options; + } + + public function setOption(string $option, $value): void + { + $this->options[$option] = $value; + } + + public function getOption(string $option) + { + return $this->options[$option] ?? null; + } +} diff --git a/src/lib/Event/UserUpdateFieldOptionsEvent.php b/src/lib/Event/UserUpdateFieldOptionsEvent.php index 6c2a62c4..97671244 100644 --- a/src/lib/Event/UserUpdateFieldOptionsEvent.php +++ b/src/lib/Event/UserUpdateFieldOptionsEvent.php @@ -12,9 +12,8 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct; use Symfony\Component\Form\FormInterface; -use Symfony\Contracts\EventDispatcher\Event; -final class UserUpdateFieldOptionsEvent extends Event +final class UserUpdateFieldOptionsEvent extends UserStructFieldOptionsEvent { /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content */ private $content; @@ -22,15 +21,6 @@ final class UserUpdateFieldOptionsEvent extends Event /** @var \Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct */ private $userUpdateStruct; - /** @var \Symfony\Component\Form\FormInterface */ - private $parentForm; - - /** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */ - private $fieldData; - - /** @var array */ - private $options; - public function __construct( Content $content, UserUpdateStruct $userUpdateStruct, @@ -40,9 +30,8 @@ public function __construct( ) { $this->content = $content; $this->userUpdateStruct = $userUpdateStruct; - $this->parentForm = $parentForm; - $this->fieldData = $fieldData; - $this->options = $options; + + parent::__construct($parentForm, $fieldData, $options); } public function getContent(): Content @@ -50,49 +39,8 @@ public function getContent(): Content return $this->content; } - public function setContent(Content $content): void - { - $this->content = $content; - } - public function getUserUpdateStruct(): UserUpdateStruct { return $this->userUpdateStruct; } - - public function getParentForm(): FormInterface - { - return $this->parentForm; - } - - public function getFieldData(): FieldData - { - return $this->fieldData; - } - - /** - * @return array - */ - public function getOptions(): array - { - return $this->options; - } - - /** - * @param array $options - */ - public function setOptions(array $options): void - { - $this->options = $options; - } - - public function setOption(string $option, $value): void - { - $this->options[$option] = $value; - } - - public function getOption(string $option) - { - return $this->options[$option] ?? null; - } } From aa1e6f995948bc6d08a752df732d5c7f12d088be Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 15 Mar 2024 11:56:12 +0100 Subject: [PATCH 03/17] IBX-7935: Further code refactor --- .../Event/ContentCreateFieldOptionsEvent.php | 47 ++----------------- .../Event/ContentUpdateFieldOptionsEvent.php | 47 ++----------------- ...sEvent.php => StructFieldOptionsEvent.php} | 8 +++- src/lib/Event/UserCreateFieldOptionsEvent.php | 2 +- src/lib/Event/UserUpdateFieldOptionsEvent.php | 2 +- 5 files changed, 15 insertions(+), 91 deletions(-) rename src/lib/Event/{UserStructFieldOptionsEvent.php => StructFieldOptionsEvent.php} (92%) diff --git a/src/lib/Event/ContentCreateFieldOptionsEvent.php b/src/lib/Event/ContentCreateFieldOptionsEvent.php index ac0d7ac3..a48e93e2 100644 --- a/src/lib/Event/ContentCreateFieldOptionsEvent.php +++ b/src/lib/Event/ContentCreateFieldOptionsEvent.php @@ -11,22 +11,12 @@ use Ibexa\Contracts\ContentForms\Data\Content\FieldData; use Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct; use Symfony\Component\Form\FormInterface; -use Symfony\Contracts\EventDispatcher\Event; -final class ContentCreateFieldOptionsEvent extends Event +final class ContentCreateFieldOptionsEvent extends StructFieldOptionsEvent { /** @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct */ private $contentCreateStruct; - /** @var \Symfony\Component\Form\FormInterface */ - private $parentForm; - - /** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */ - private $fieldData; - - /** @var array */ - private $options; - public function __construct( ContentCreateStruct $contentCreateStruct, FormInterface $parentForm, @@ -34,45 +24,14 @@ public function __construct( array $options ) { $this->contentCreateStruct = $contentCreateStruct; - $this->parentForm = $parentForm; - $this->fieldData = $fieldData; - $this->options = $options; + + parent::__construct($parentForm, $fieldData, $options); } public function getContentCreateStruct(): ContentCreateStruct { return $this->contentCreateStruct; } - - public function getParentForm(): FormInterface - { - return $this->parentForm; - } - - public function getFieldData(): FieldData - { - return $this->fieldData; - } - - public function getOptions(): array - { - return $this->options; - } - - public function setOptions(array $options): void - { - $this->options = $options; - } - - public function setOption(string $option, $value): void - { - $this->options[$option] = $value; - } - - public function getOption(string $option) - { - return $this->options[$option] ?? null; - } } class_alias(ContentCreateFieldOptionsEvent::class, 'EzSystems\EzPlatformContentForms\Event\ContentCreateFieldOptionsEvent'); diff --git a/src/lib/Event/ContentUpdateFieldOptionsEvent.php b/src/lib/Event/ContentUpdateFieldOptionsEvent.php index a17dfb1d..d44ebb2e 100644 --- a/src/lib/Event/ContentUpdateFieldOptionsEvent.php +++ b/src/lib/Event/ContentUpdateFieldOptionsEvent.php @@ -12,9 +12,8 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\Content\ContentUpdateStruct; use Symfony\Component\Form\FormInterface; -use Symfony\Contracts\EventDispatcher\Event; -final class ContentUpdateFieldOptionsEvent extends Event +final class ContentUpdateFieldOptionsEvent extends StructFieldOptionsEvent { /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content */ private $content; @@ -22,15 +21,6 @@ final class ContentUpdateFieldOptionsEvent extends Event /** @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentUpdateStruct */ private $contentUpdateStruct; - /** @var \Symfony\Component\Form\FormInterface */ - private $parentForm; - - /** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */ - private $fieldData; - - /** @var array */ - private $options; - public function __construct( Content $content, ContentUpdateStruct $contentUpdateStruct, @@ -40,9 +30,8 @@ public function __construct( ) { $this->content = $content; $this->contentUpdateStruct = $contentUpdateStruct; - $this->parentForm = $parentForm; - $this->fieldData = $fieldData; - $this->options = $options; + + parent::__construct($parentForm, $fieldData, $options); } public function getContent(): Content @@ -54,36 +43,6 @@ public function getContentUpdateStruct(): ContentUpdateStruct { return $this->contentUpdateStruct; } - - public function getParentForm(): FormInterface - { - return $this->parentForm; - } - - public function getFieldData(): FieldData - { - return $this->fieldData; - } - - public function getOptions(): array - { - return $this->options; - } - - public function setOptions(array $options): void - { - $this->options = $options; - } - - public function setOption(string $option, $value): void - { - $this->options[$option] = $value; - } - - public function getOption(string $option) - { - return $this->options[$option] ?? null; - } } class_alias(ContentUpdateFieldOptionsEvent::class, 'EzSystems\EzPlatformContentForms\Event\ContentUpdateFieldOptionsEvent'); diff --git a/src/lib/Event/UserStructFieldOptionsEvent.php b/src/lib/Event/StructFieldOptionsEvent.php similarity index 92% rename from src/lib/Event/UserStructFieldOptionsEvent.php rename to src/lib/Event/StructFieldOptionsEvent.php index 541dd61a..c1339d84 100644 --- a/src/lib/Event/UserStructFieldOptionsEvent.php +++ b/src/lib/Event/StructFieldOptionsEvent.php @@ -12,7 +12,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Contracts\EventDispatcher\Event; -abstract class UserStructFieldOptionsEvent extends Event +abstract class StructFieldOptionsEvent extends Event { /** @var \Symfony\Component\Form\FormInterface */ protected $parentForm; @@ -59,11 +59,17 @@ public function setOptions(array $options): void $this->options = $options; } + /** + * @param mixed $value + */ public function setOption(string $option, $value): void { $this->options[$option] = $value; } + /** + * @return mixed|null + */ public function getOption(string $option) { return $this->options[$option] ?? null; diff --git a/src/lib/Event/UserCreateFieldOptionsEvent.php b/src/lib/Event/UserCreateFieldOptionsEvent.php index 7c3cb905..321d8634 100644 --- a/src/lib/Event/UserCreateFieldOptionsEvent.php +++ b/src/lib/Event/UserCreateFieldOptionsEvent.php @@ -12,7 +12,7 @@ use Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct; use Symfony\Component\Form\FormInterface; -final class UserCreateFieldOptionsEvent extends UserStructFieldOptionsEvent +final class UserCreateFieldOptionsEvent extends StructFieldOptionsEvent { /** @var \Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct */ private $userCreateStruct; diff --git a/src/lib/Event/UserUpdateFieldOptionsEvent.php b/src/lib/Event/UserUpdateFieldOptionsEvent.php index 97671244..ae9fb1e5 100644 --- a/src/lib/Event/UserUpdateFieldOptionsEvent.php +++ b/src/lib/Event/UserUpdateFieldOptionsEvent.php @@ -13,7 +13,7 @@ use Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct; use Symfony\Component\Form\FormInterface; -final class UserUpdateFieldOptionsEvent extends UserStructFieldOptionsEvent +final class UserUpdateFieldOptionsEvent extends StructFieldOptionsEvent { /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content */ private $content; From 59f4b39fe058d65b462dd6fec263f812469dba30 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Thu, 9 May 2024 20:10:34 +0200 Subject: [PATCH 04/17] IBX-7935: Applied review remarks --- src/bundle/Controller/UserController.php | 2 +- src/lib/Event/StructFieldOptionsEvent.php | 6 +-- src/lib/Event/UserCreateFieldOptionsEvent.php | 2 +- src/lib/Event/UserUpdateFieldOptionsEvent.php | 4 +- src/lib/Form/Type/Content/BaseContentType.php | 37 ++++++++++++++++--- .../Form/Type/Content/ContentFieldType.php | 11 +++--- .../Form/Type/Content/FieldCollectionType.php | 23 +++++++----- 7 files changed, 58 insertions(+), 27 deletions(-) diff --git a/src/bundle/Controller/UserController.php b/src/bundle/Controller/UserController.php index d68ef09d..a099666e 100644 --- a/src/bundle/Controller/UserController.php +++ b/src/bundle/Controller/UserController.php @@ -55,7 +55,7 @@ class UserController extends Controller private $groupedContentFormFieldsProvider; /** @var \Ibexa\Contracts\Core\Repository\ContentService */ - private $contentService; + private ContentService $contentService; public function __construct( ContentTypeService $contentTypeService, diff --git a/src/lib/Event/StructFieldOptionsEvent.php b/src/lib/Event/StructFieldOptionsEvent.php index c1339d84..5a1b4c27 100644 --- a/src/lib/Event/StructFieldOptionsEvent.php +++ b/src/lib/Event/StructFieldOptionsEvent.php @@ -15,13 +15,13 @@ abstract class StructFieldOptionsEvent extends Event { /** @var \Symfony\Component\Form\FormInterface */ - protected $parentForm; + protected FormInterface $parentForm; /** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */ - protected $fieldData; + protected FieldData $fieldData; /** @var array */ - protected $options; + protected array $options; public function __construct( FormInterface $parentForm, diff --git a/src/lib/Event/UserCreateFieldOptionsEvent.php b/src/lib/Event/UserCreateFieldOptionsEvent.php index 321d8634..42d44456 100644 --- a/src/lib/Event/UserCreateFieldOptionsEvent.php +++ b/src/lib/Event/UserCreateFieldOptionsEvent.php @@ -15,7 +15,7 @@ final class UserCreateFieldOptionsEvent extends StructFieldOptionsEvent { /** @var \Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct */ - private $userCreateStruct; + private UserCreateStruct $userCreateStruct; public function __construct( UserCreateStruct $userCreateStruct, diff --git a/src/lib/Event/UserUpdateFieldOptionsEvent.php b/src/lib/Event/UserUpdateFieldOptionsEvent.php index ae9fb1e5..aa1fc884 100644 --- a/src/lib/Event/UserUpdateFieldOptionsEvent.php +++ b/src/lib/Event/UserUpdateFieldOptionsEvent.php @@ -16,10 +16,10 @@ final class UserUpdateFieldOptionsEvent extends StructFieldOptionsEvent { /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content */ - private $content; + private Content $content; /** @var \Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct */ - private $userUpdateStruct; + private UserUpdateStruct $userUpdateStruct; public function __construct( Content $content, diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index 51ec4161..ebfac390 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -8,12 +8,17 @@ namespace Ibexa\ContentForms\Form\Type\Content; +use Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct; +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; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; +use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -42,10 +47,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'mainLanguageCode' => $options['mainLanguageCode'], 'location' => $options['location'] ?? null, 'content' => $options['content'] ?? null, - 'contentCreateStruct' => $options['contentCreateStruct'] ?? null, - 'contentUpdateStruct' => $options['contentUpdateStruct'] ?? null, - 'userCreateStruct' => $options['userCreateStruct'] ?? null, - 'userUpdateStruct' => $options['userUpdateStruct'] ?? null, + 'contentCreateStruct' => $options['contentCreateStruct'] ?? null, // deprecated + 'contentUpdateStruct' => $options['contentUpdateStruct'] ?? null, // deprecated + 'userCreateStruct' => $options['userCreateStruct'] ?? null, // deprecated + 'userUpdateStruct' => $options['userUpdateStruct'] ?? null, // deprecated + 'struct' => $options['struct'], ], ]) ->add('redirectUrlAfterPublish', HiddenType::class, [ @@ -63,8 +69,27 @@ public function buildView(FormView $view, FormInterface $form, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver - ->setDefaults(['translation_domain' => 'ibexa_content_forms_content']) - ->setRequired(['languageCode', 'mainLanguageCode']); + ->setDefaults([ + 'translation_domain' => 'ibexa_content_forms_content', + 'struct' => null, + ]) + ->setAllowedTypes( + 'struct', + [ + 'null', + ContentCreateStruct::class, + ContentUpdateStruct::class, + UserCreateStruct::class, + UserUpdateStruct::class, + ], + ) + ->setRequired(['languageCode', 'mainLanguageCode', 'struct']) + ->setNormalizer('struct', static function (Options $options, $value) { + return $options['userUpdateStruct'] + ?? $options['userCreateStruct'] + ?? $options['contentUpdateStruct'] + ?? $options['contentCreateStruct']; + }); } } diff --git a/src/lib/Form/Type/Content/ContentFieldType.php b/src/lib/Form/Type/Content/ContentFieldType.php index 78ce734a..f9d9e9a7 100644 --- a/src/lib/Form/Type/Content/ContentFieldType.php +++ b/src/lib/Form/Type/Content/ContentFieldType.php @@ -46,14 +46,15 @@ public function configureOptions(OptionsResolver $resolver) ->setDefaults([ 'content' => null, 'location' => null, - 'contentCreateStruct' => null, - 'contentUpdateStruct' => null, - 'userCreateStruct' => null, - 'userUpdateStruct' => null, + 'contentCreateStruct' => null, // deprecated + 'contentUpdateStruct' => null, // deprecated + 'userCreateStruct' => null, // deprecated + 'userUpdateStruct' => null, // deprecated 'data_class' => FieldData::class, 'translation_domain' => 'ibexa_content_forms_content', + 'struct' => null, ]) - ->setRequired(['languageCode', 'mainLanguageCode']); + ->setRequired(['languageCode', 'mainLanguageCode', 'struct']); } public function buildView(FormView $view, FormInterface $form, array $options) diff --git a/src/lib/Form/Type/Content/FieldCollectionType.php b/src/lib/Form/Type/Content/FieldCollectionType.php index 39e9c32c..1a9b30eb 100644 --- a/src/lib/Form/Type/Content/FieldCollectionType.php +++ b/src/lib/Form/Type/Content/FieldCollectionType.php @@ -14,6 +14,10 @@ use Ibexa\ContentForms\Event\UserCreateFieldOptionsEvent; use Ibexa\ContentForms\Event\UserUpdateFieldOptionsEvent; use Ibexa\Contracts\ContentForms\Data\Content\FieldData; +use Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct; +use Ibexa\Core\Repository\Values\Content\ContentCreateStruct; +use Ibexa\Core\Repository\Values\Content\ContentUpdateStruct; +use Ibexa\Core\Repository\Values\User\UserCreateStruct; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; @@ -61,12 +65,12 @@ public function buildForm( private function isContentCreate(array $entryOptions): bool { - return !empty($entryOptions['contentCreateStruct']); + return !empty($entryOptions['struct']) && $entryOptions['struct'] instanceof ContentCreateStruct; } private function isContentUpdate(array $entryOptions): bool { - return !empty($entryOptions['content']) && !empty($entryOptions['contentUpdateStruct']); + return !empty($entryOptions['struct']) && $entryOptions['struct'] instanceof ContentUpdateStruct; } /** @@ -74,7 +78,7 @@ private function isContentUpdate(array $entryOptions): bool */ private function isUserCreate(array $entryOptions): bool { - return !empty($entryOptions['userCreateStruct']); + return !empty($entryOptions['struct']) && $entryOptions['struct'] instanceof UserCreateStruct; } /** @@ -82,25 +86,26 @@ private function isUserCreate(array $entryOptions): bool */ private function isUserUpdate(array $entryOptions): bool { - return !empty($entryOptions['userUpdateStruct']); + return !empty($entryOptions['struct']) && $entryOptions['struct'] instanceof UserUpdateStruct; } /** * @param array $entryOptions * - * @return array $entryOptions + * @return array */ private function dispatchFieldOptionsEvent( FieldData $entryData, array $entryOptions, FormInterface $form ): array { + dump($entryOptions); if ($this->isContentUpdate($entryOptions)) { /** @var \Ibexa\ContentForms\Event\ContentUpdateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ $contentUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch( new ContentUpdateFieldOptionsEvent( $entryOptions['content'], - $entryOptions['contentUpdateStruct'], + $entryOptions['struct'], $form, $entryData, $entryOptions @@ -113,7 +118,7 @@ private function dispatchFieldOptionsEvent( /** @var \Ibexa\ContentForms\Event\ContentCreateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ $contentCreateFieldOptionsEvent = $this->eventDispatcher->dispatch( new ContentCreateFieldOptionsEvent( - $entryOptions['contentCreateStruct'], + $entryOptions['struct'], $form, $entryData, $entryOptions @@ -126,7 +131,7 @@ private function dispatchFieldOptionsEvent( /** @var \Ibexa\ContentForms\Event\UserCreateFieldOptionsEvent $userCreateFieldOptionsEvent */ $userCreateFieldOptionsEvent = $this->eventDispatcher->dispatch( new UserCreateFieldOptionsEvent( - $entryOptions['userCreateStruct'], + $entryOptions['struct'], $form, $entryData, $entryOptions @@ -140,7 +145,7 @@ private function dispatchFieldOptionsEvent( $userUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch( new UserUpdateFieldOptionsEvent( $entryOptions['content'], - $entryOptions['userUpdateStruct'], + $entryOptions['struct'], $form, $entryData, $entryOptions From b4e534a9c8287f60fe7149e50d940e991a687754 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Thu, 9 May 2024 20:11:54 +0200 Subject: [PATCH 05/17] IBX-7935: Fixup --- src/lib/Form/Type/Content/BaseContentType.php | 2 -- src/lib/Form/Type/Content/ContentFieldType.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index ebfac390..5bb57d63 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -49,8 +49,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'content' => $options['content'] ?? null, 'contentCreateStruct' => $options['contentCreateStruct'] ?? null, // deprecated 'contentUpdateStruct' => $options['contentUpdateStruct'] ?? null, // deprecated - 'userCreateStruct' => $options['userCreateStruct'] ?? null, // deprecated - 'userUpdateStruct' => $options['userUpdateStruct'] ?? null, // deprecated 'struct' => $options['struct'], ], ]) diff --git a/src/lib/Form/Type/Content/ContentFieldType.php b/src/lib/Form/Type/Content/ContentFieldType.php index f9d9e9a7..3ac7f274 100644 --- a/src/lib/Form/Type/Content/ContentFieldType.php +++ b/src/lib/Form/Type/Content/ContentFieldType.php @@ -48,8 +48,6 @@ public function configureOptions(OptionsResolver $resolver) 'location' => null, 'contentCreateStruct' => null, // deprecated 'contentUpdateStruct' => null, // deprecated - 'userCreateStruct' => null, // deprecated - 'userUpdateStruct' => null, // deprecated 'data_class' => FieldData::class, 'translation_domain' => 'ibexa_content_forms_content', 'struct' => null, From adb6887c1a00ffaadf7d2726acf587a2308dc678 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 10 May 2024 12:36:54 +0200 Subject: [PATCH 06/17] IBX-7935: Applied review remarks --- src/bundle/Controller/UserController.php | 6 +-- src/lib/Form/Type/Content/BaseContentType.php | 41 +++++++++++++++---- .../Form/Type/Content/ContentFieldType.php | 34 +++++++++++++-- .../Form/Type/Content/FieldCollectionType.php | 1 - src/lib/Form/Type/User/UserCreateType.php | 6 ++- src/lib/Form/Type/User/UserUpdateType.php | 6 ++- 6 files changed, 76 insertions(+), 18 deletions(-) diff --git a/src/bundle/Controller/UserController.php b/src/bundle/Controller/UserController.php index a099666e..7e7ffc3a 100644 --- a/src/bundle/Controller/UserController.php +++ b/src/bundle/Controller/UserController.php @@ -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); @@ -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); diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index 5bb57d63..d416254f 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -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; @@ -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'], ], ]) @@ -70,6 +70,8 @@ public function configureOptions(OptionsResolver $resolver) ->setDefaults([ 'translation_domain' => 'ibexa_content_forms_content', 'struct' => null, + 'contentCreateStruct' => null, + 'contentUpdateStruct' => null, ]) ->setAllowedTypes( 'struct', @@ -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.' + ); } } diff --git a/src/lib/Form/Type/Content/ContentFieldType.php b/src/lib/Form/Type/Content/ContentFieldType.php index 3ac7f274..eec52d44 100644 --- a/src/lib/Form/Type/Content/ContentFieldType.php +++ b/src/lib/Form/Type/Content/ContentFieldType.php @@ -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; @@ -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) diff --git a/src/lib/Form/Type/Content/FieldCollectionType.php b/src/lib/Form/Type/Content/FieldCollectionType.php index 1a9b30eb..654ff464 100644 --- a/src/lib/Form/Type/Content/FieldCollectionType.php +++ b/src/lib/Form/Type/Content/FieldCollectionType.php @@ -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( diff --git a/src/lib/Form/Type/User/UserCreateType.php b/src/lib/Form/Type/User/UserCreateType.php index d1adbc35..b1056cf1 100644 --- a/src/lib/Form/Type/User/UserCreateType.php +++ b/src/lib/Form/Type/User/UserCreateType.php @@ -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; @@ -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); } } diff --git a/src/lib/Form/Type/User/UserUpdateType.php b/src/lib/Form/Type/User/UserUpdateType.php index 2d95dd6c..2cb271ea 100644 --- a/src/lib/Form/Type/User/UserUpdateType.php +++ b/src/lib/Form/Type/User/UserUpdateType.php @@ -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; @@ -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); } } From 66327fcecbb0b330841751a467b20c491784afef Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 10 May 2024 12:48:52 +0200 Subject: [PATCH 07/17] IBX-7935: Refactored options --- src/lib/Form/Type/Content/BaseContentType.php | 4 +--- src/lib/Form/Type/Content/ContentFieldType.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index d416254f..65b85f0d 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -67,23 +67,21 @@ public function buildView(FormView $view, FormInterface $form, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver + ->setRequired(['languageCode', 'mainLanguageCode', 'struct']) ->setDefaults([ 'translation_domain' => 'ibexa_content_forms_content', - 'struct' => null, 'contentCreateStruct' => null, 'contentUpdateStruct' => null, ]) ->setAllowedTypes( 'struct', [ - 'null', ContentCreateStruct::class, ContentUpdateStruct::class, UserCreateStruct::class, UserUpdateStruct::class, ], ) - ->setRequired(['languageCode', 'mainLanguageCode', 'struct']) ->setNormalizer('struct', static function (Options $options, $value) { if ($value !== null) { return $value; diff --git a/src/lib/Form/Type/Content/ContentFieldType.php b/src/lib/Form/Type/Content/ContentFieldType.php index eec52d44..fe1756a5 100644 --- a/src/lib/Form/Type/Content/ContentFieldType.php +++ b/src/lib/Form/Type/Content/ContentFieldType.php @@ -47,6 +47,7 @@ public function getBlockPrefix() public function configureOptions(OptionsResolver $resolver) { $resolver + ->setRequired(['languageCode', 'mainLanguageCode', 'struct']) ->setDefaults([ 'content' => null, 'location' => null, @@ -54,12 +55,10 @@ public function configureOptions(OptionsResolver $resolver) 'contentUpdateStruct' => null, 'data_class' => FieldData::class, 'translation_domain' => 'ibexa_content_forms_content', - 'struct' => null, ]) ->setAllowedTypes( 'struct', [ - 'null', ContentCreateStruct::class, ContentUpdateStruct::class, UserCreateStruct::class, @@ -68,7 +67,6 @@ public function configureOptions(OptionsResolver $resolver) ) ->setAllowedTypes('contentCreateStruct', ['null', ContentCreateStruct::class]) ->setAllowedTypes('contentUpdateStruct', ['null', ContentUpdateStruct::class]) - ->setRequired(['languageCode', 'mainLanguageCode', 'struct']) ->setDeprecated( 'contentCreateStruct', 'ibexa/content-forms', From 292ee47846746bf603b968805966bd1fb8e1ff93 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 10 May 2024 12:51:43 +0200 Subject: [PATCH 08/17] IBX-7935: Refactored options --- src/lib/Form/Type/User/UserCreateType.php | 2 +- src/lib/Form/Type/User/UserUpdateType.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/Form/Type/User/UserCreateType.php b/src/lib/Form/Type/User/UserCreateType.php index b1056cf1..2fd75bcc 100644 --- a/src/lib/Form/Type/User/UserCreateType.php +++ b/src/lib/Form/Type/User/UserCreateType.php @@ -47,8 +47,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver): void { $resolver + ->setRequired('struct') ->setDefaults([ - 'struct' => null, 'data_class' => UserCreateData::class, 'intent' => 'create', 'translation_domain' => 'ibexa_content_forms_user', diff --git a/src/lib/Form/Type/User/UserUpdateType.php b/src/lib/Form/Type/User/UserUpdateType.php index 2cb271ea..3fcd4cf6 100644 --- a/src/lib/Form/Type/User/UserUpdateType.php +++ b/src/lib/Form/Type/User/UserUpdateType.php @@ -47,10 +47,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver): void { $resolver + ->setRequired('struct') ->setDefaults([ 'location' => null, 'content' => null, - 'struct' => null, 'data_class' => UserUpdateData::class, 'intent' => 'update', 'translation_domain' => 'ibexa_content_forms_user', From 9d790b3a7c218f892a2da1046ce27516ad1e8047 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 10 May 2024 13:06:12 +0200 Subject: [PATCH 09/17] IBX-7935: Allowed BC --- src/lib/Form/Type/Content/BaseContentType.php | 6 ++++-- src/lib/Form/Type/Content/ContentFieldType.php | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index 65b85f0d..12bbc66a 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -72,17 +72,19 @@ public function configureOptions(OptionsResolver $resolver) 'translation_domain' => 'ibexa_content_forms_content', 'contentCreateStruct' => null, 'contentUpdateStruct' => null, + 'struct' => null, ]) ->setAllowedTypes( 'struct', [ + 'null', ContentCreateStruct::class, ContentUpdateStruct::class, UserCreateStruct::class, UserUpdateStruct::class, ], ) - ->setNormalizer('struct', static function (Options $options, $value) { + ->addNormalizer('struct', static function (Options $options, $value) { if ($value !== null) { return $value; } @@ -100,7 +102,7 @@ public function configureOptions(OptionsResolver $resolver) } return null; - }) + }, true) ->setDeprecated( 'contentCreateStruct', 'ibexa/content-forms', diff --git a/src/lib/Form/Type/Content/ContentFieldType.php b/src/lib/Form/Type/Content/ContentFieldType.php index fe1756a5..71b52b06 100644 --- a/src/lib/Form/Type/Content/ContentFieldType.php +++ b/src/lib/Form/Type/Content/ContentFieldType.php @@ -59,6 +59,7 @@ public function configureOptions(OptionsResolver $resolver) ->setAllowedTypes( 'struct', [ + 'null', ContentCreateStruct::class, ContentUpdateStruct::class, UserCreateStruct::class, From 2a493e75398a75a910c976a4813d086cc88add03 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 10 May 2024 15:52:16 +0200 Subject: [PATCH 10/17] IBX-7935: Refactored default value for the `struct` option --- src/lib/Form/Type/Content/BaseContentType.php | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index 12bbc66a..1c457272 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -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', From 5de6039720f0d664c3903174b629b9e89b048301 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Mon, 13 May 2024 12:21:48 +0200 Subject: [PATCH 11/17] IBX-7935: Refactored `FieldCollectionType` --- .../Form/Type/Content/FieldCollectionType.php | 167 +++++++++++------- 1 file changed, 100 insertions(+), 67 deletions(-) diff --git a/src/lib/Form/Type/Content/FieldCollectionType.php b/src/lib/Form/Type/Content/FieldCollectionType.php index 654ff464..fb09e403 100644 --- a/src/lib/Form/Type/Content/FieldCollectionType.php +++ b/src/lib/Form/Type/Content/FieldCollectionType.php @@ -63,30 +63,102 @@ public function buildForm( }); } - private function isContentCreate(array $entryOptions): bool - { - return !empty($entryOptions['struct']) && $entryOptions['struct'] instanceof ContentCreateStruct; + /** + * @param array $entryOptions + * + * @return array + */ + private function dispatchContentUpdateEvent( + FieldData $entryData, + array $entryOptions, + FormInterface $form + ): array { + /** @var \Ibexa\ContentForms\Event\ContentUpdateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ + $contentUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch( + new ContentUpdateFieldOptionsEvent( + $entryOptions['content'], + $entryOptions['struct'], + $form, + $entryData, + $entryOptions + ), + ContentFormEvents::CONTENT_EDIT_FIELD_OPTIONS + ); + + return $contentUpdateFieldOptionsEvent->getOptions(); } - private function isContentUpdate(array $entryOptions): bool - { - return !empty($entryOptions['struct']) && $entryOptions['struct'] instanceof ContentUpdateStruct; + /** + * @param array $entryOptions + * + * @return array + */ + private function dispatchContentCreateEvent( + FieldData $entryData, + array $entryOptions, + FormInterface $form + ): array { + /** @var \Ibexa\ContentForms\Event\ContentCreateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ + $contentCreateFieldOptionsEvent = $this->eventDispatcher->dispatch( + new ContentCreateFieldOptionsEvent( + $entryOptions['struct'], + $form, + $entryData, + $entryOptions + ), + ContentFormEvents::CONTENT_CREATE_FIELD_OPTIONS + ); + + return $contentCreateFieldOptionsEvent->getOptions(); } /** * @param array $entryOptions + * + * @return array */ - private function isUserCreate(array $entryOptions): bool - { - return !empty($entryOptions['struct']) && $entryOptions['struct'] instanceof UserCreateStruct; + private function dispatchUserCreateEvent( + FieldData $entryData, + array $entryOptions, + FormInterface $form + ): array { + /** @var \Ibexa\ContentForms\Event\UserCreateFieldOptionsEvent $userCreateFieldOptionsEvent */ + $userCreateFieldOptionsEvent = $this->eventDispatcher->dispatch( + new UserCreateFieldOptionsEvent( + $entryOptions['struct'], + $form, + $entryData, + $entryOptions + ), + ContentFormEvents::USER_CREATE_FIELD_OPTIONS + ); + + return $userCreateFieldOptionsEvent->getOptions(); } /** * @param array $entryOptions + * + * @return array */ - private function isUserUpdate(array $entryOptions): bool - { - return !empty($entryOptions['struct']) && $entryOptions['struct'] instanceof UserUpdateStruct; + private function dispatchUserUpdateEvent( + FieldData $entryData, + array $entryOptions, + FormInterface $form + ): array { + /** @var \Ibexa\ContentForms\Event\UserUpdateFieldOptionsEvent $userUpdateFieldOptionsEvent */ + $userUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch( + new UserUpdateFieldOptionsEvent( + $entryOptions['content'], + $entryOptions['struct'], + $form, + $entryData, + $entryOptions + ), + ContentFormEvents::USER_EDIT_FIELD_OPTIONS + ); + + return $userUpdateFieldOptionsEvent->getOptions(); } /** @@ -99,63 +171,24 @@ private function dispatchFieldOptionsEvent( array $entryOptions, FormInterface $form ): array { - if ($this->isContentUpdate($entryOptions)) { - /** @var \Ibexa\ContentForms\Event\ContentUpdateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ - $contentUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch( - new ContentUpdateFieldOptionsEvent( - $entryOptions['content'], - $entryOptions['struct'], - $form, - $entryData, - $entryOptions - ), - ContentFormEvents::CONTENT_EDIT_FIELD_OPTIONS - ); - - $entryOptions = $contentUpdateFieldOptionsEvent->getOptions(); - } elseif ($this->isContentCreate($entryOptions)) { - /** @var \Ibexa\ContentForms\Event\ContentCreateFieldOptionsEvent $contentUpdateFieldOptionsEvent */ - $contentCreateFieldOptionsEvent = $this->eventDispatcher->dispatch( - new ContentCreateFieldOptionsEvent( - $entryOptions['struct'], - $form, - $entryData, - $entryOptions - ), - ContentFormEvents::CONTENT_CREATE_FIELD_OPTIONS - ); - - $entryOptions = $contentCreateFieldOptionsEvent->getOptions(); - } elseif ($this->isUserCreate($entryOptions)) { - /** @var \Ibexa\ContentForms\Event\UserCreateFieldOptionsEvent $userCreateFieldOptionsEvent */ - $userCreateFieldOptionsEvent = $this->eventDispatcher->dispatch( - new UserCreateFieldOptionsEvent( - $entryOptions['struct'], - $form, - $entryData, - $entryOptions - ), - ContentFormEvents::USER_CREATE_FIELD_OPTIONS - ); - - $entryOptions = $userCreateFieldOptionsEvent->getOptions(); - } elseif ($this->isUserUpdate($entryOptions)) { - /** @var \Ibexa\ContentForms\Event\UserUpdateFieldOptionsEvent $userUpdateFieldOptionsEvent */ - $userUpdateFieldOptionsEvent = $this->eventDispatcher->dispatch( - new UserUpdateFieldOptionsEvent( - $entryOptions['content'], - $entryOptions['struct'], - $form, - $entryData, - $entryOptions - ), - ContentFormEvents::USER_EDIT_FIELD_OPTIONS - ); - - $entryOptions = $userUpdateFieldOptionsEvent->getOptions(); + if (!isset($entryOptions['struct'])) { + return $entryOptions; } - return $entryOptions; + $struct = $entryOptions['struct']; + + switch ($struct) { + case $struct instanceof ContentCreateStruct: + return $this->dispatchContentCreateEvent($entryData, $entryOptions, $form); + case $struct instanceof ContentUpdateStruct: + return $this->dispatchContentUpdateEvent($entryData, $entryOptions, $form); + case $struct instanceof UserCreateStruct: + return $this->dispatchUserCreateEvent($entryData, $entryOptions, $form); + case $struct instanceof UserUpdateStruct: + return $this->dispatchUserUpdateEvent($entryData, $entryOptions, $form); + default: + return $entryOptions; + } } } From 1eea6899c4ce7b1472713d60d437c9cdd6b86f9a Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Mon, 13 May 2024 12:27:07 +0200 Subject: [PATCH 12/17] IBX-7935: Fixed translation domain --- src/lib/Form/Type/Content/BaseContentType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index 1c457272..d0fa393a 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -51,6 +51,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'contentUpdateStruct' => $options['contentUpdateStruct'] ?? null, 'struct' => $options['struct'], ], + 'translation_domain' => 'ibexa_content_forms_content', ]) ->add('redirectUrlAfterPublish', HiddenType::class, [ 'required' => false, From ce43276cf53f984ba048b1bd547c9ec43b9fa3c7 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Mon, 13 May 2024 14:20:45 +0200 Subject: [PATCH 13/17] IBX-7935: Applied review remark --- src/lib/Form/Type/Content/FieldCollectionType.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/Form/Type/Content/FieldCollectionType.php b/src/lib/Form/Type/Content/FieldCollectionType.php index fb09e403..9f53e41d 100644 --- a/src/lib/Form/Type/Content/FieldCollectionType.php +++ b/src/lib/Form/Type/Content/FieldCollectionType.php @@ -23,6 +23,7 @@ use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class FieldCollectionType extends CollectionType @@ -63,6 +64,13 @@ public function buildForm( }); } + public function configureOptions(OptionsResolver $resolver): void + { + parent::configureOptions($resolver); + + $resolver->setDefault('translation_domain', 'ibexa_content_forms_content'); + } + /** * @param array $entryOptions * From 720bc9457b8236a2bb43062bff48676dd140ebb9 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Mon, 13 May 2024 14:34:54 +0200 Subject: [PATCH 14/17] IBX-7935: Removed unnecessary annotations --- src/bundle/Controller/UserController.php | 1 - src/lib/Event/ContentCreateFieldOptionsEvent.php | 1 - src/lib/Event/StructFieldOptionsEvent.php | 2 -- src/lib/Event/UserUpdateFieldOptionsEvent.php | 2 -- 4 files changed, 6 deletions(-) diff --git a/src/bundle/Controller/UserController.php b/src/bundle/Controller/UserController.php index 7e7ffc3a..5755588b 100644 --- a/src/bundle/Controller/UserController.php +++ b/src/bundle/Controller/UserController.php @@ -54,7 +54,6 @@ class UserController extends Controller /** @var \Ibexa\Contracts\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProviderInterface */ private $groupedContentFormFieldsProvider; - /** @var \Ibexa\Contracts\Core\Repository\ContentService */ private ContentService $contentService; public function __construct( diff --git a/src/lib/Event/ContentCreateFieldOptionsEvent.php b/src/lib/Event/ContentCreateFieldOptionsEvent.php index a48e93e2..d95d93d3 100644 --- a/src/lib/Event/ContentCreateFieldOptionsEvent.php +++ b/src/lib/Event/ContentCreateFieldOptionsEvent.php @@ -14,7 +14,6 @@ final class ContentCreateFieldOptionsEvent extends StructFieldOptionsEvent { - /** @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct */ private $contentCreateStruct; public function __construct( diff --git a/src/lib/Event/StructFieldOptionsEvent.php b/src/lib/Event/StructFieldOptionsEvent.php index 5a1b4c27..b3a15e8a 100644 --- a/src/lib/Event/StructFieldOptionsEvent.php +++ b/src/lib/Event/StructFieldOptionsEvent.php @@ -14,10 +14,8 @@ abstract class StructFieldOptionsEvent extends Event { - /** @var \Symfony\Component\Form\FormInterface */ protected FormInterface $parentForm; - /** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */ protected FieldData $fieldData; /** @var array */ diff --git a/src/lib/Event/UserUpdateFieldOptionsEvent.php b/src/lib/Event/UserUpdateFieldOptionsEvent.php index aa1fc884..55a32c5b 100644 --- a/src/lib/Event/UserUpdateFieldOptionsEvent.php +++ b/src/lib/Event/UserUpdateFieldOptionsEvent.php @@ -15,10 +15,8 @@ final class UserUpdateFieldOptionsEvent extends StructFieldOptionsEvent { - /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content */ private Content $content; - /** @var \Ibexa\Contracts\Core\Repository\Values\User\UserUpdateStruct */ private UserUpdateStruct $userUpdateStruct; public function __construct( From 09edc0eb3cc47a7617ca9d967c2e4be7413a3200 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Mon, 13 May 2024 14:48:29 +0200 Subject: [PATCH 15/17] IBX-7935: Removed unnecessary annotations --- src/lib/Event/ContentCreateFieldOptionsEvent.php | 1 + src/lib/Event/UserCreateFieldOptionsEvent.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Event/ContentCreateFieldOptionsEvent.php b/src/lib/Event/ContentCreateFieldOptionsEvent.php index d95d93d3..a48e93e2 100644 --- a/src/lib/Event/ContentCreateFieldOptionsEvent.php +++ b/src/lib/Event/ContentCreateFieldOptionsEvent.php @@ -14,6 +14,7 @@ final class ContentCreateFieldOptionsEvent extends StructFieldOptionsEvent { + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct */ private $contentCreateStruct; public function __construct( diff --git a/src/lib/Event/UserCreateFieldOptionsEvent.php b/src/lib/Event/UserCreateFieldOptionsEvent.php index 42d44456..7fa212bf 100644 --- a/src/lib/Event/UserCreateFieldOptionsEvent.php +++ b/src/lib/Event/UserCreateFieldOptionsEvent.php @@ -14,7 +14,6 @@ final class UserCreateFieldOptionsEvent extends StructFieldOptionsEvent { - /** @var \Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct */ private UserCreateStruct $userCreateStruct; public function __construct( From 3f77e4ae9512feeea227736dd591e73f079a098c Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Tue, 28 May 2024 12:00:15 +0200 Subject: [PATCH 16/17] IBX-7935: Fixed `data` option not being passed to `struct` --- src/lib/Form/Type/Content/BaseContentType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index d0fa393a..8f742826 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -78,6 +78,7 @@ public function configureOptions(OptionsResolver $resolver) ?? $options['userCreateStruct'] ?? $options['contentUpdateStruct'] ?? $options['contentCreateStruct'] + ?? $options['data'] ?? null; }) ->setDefaults([ From e4523eb095d53edb3b5d4ee26d63aa8b9719821a Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Wed, 29 May 2024 11:37:07 +0200 Subject: [PATCH 17/17] IBX-7935: Allow `struct` to be `null` option --- src/lib/Form/Type/Content/BaseContentType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index 8f742826..515f848c 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -78,7 +78,6 @@ public function configureOptions(OptionsResolver $resolver) ?? $options['userCreateStruct'] ?? $options['contentUpdateStruct'] ?? $options['contentCreateStruct'] - ?? $options['data'] ?? null; }) ->setDefaults([ @@ -89,6 +88,7 @@ public function configureOptions(OptionsResolver $resolver) ->setAllowedTypes( 'struct', [ + 'null', ContentCreateStruct::class, ContentUpdateStruct::class, UserCreateStruct::class,