diff --git a/src/bundle/Controller/UserController.php b/src/bundle/Controller/UserController.php index 1f94138e..5755588b 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,8 @@ class UserController extends Controller /** @var \Ibexa\Contracts\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProviderInterface */ private $groupedContentFormFieldsProvider; + private ContentService $contentService; + public function __construct( ContentTypeService $contentTypeService, UserService $userService, @@ -61,7 +64,8 @@ public function __construct( ActionDispatcherInterface $userActionDispatcher, PermissionResolver $permissionResolver, UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider, - GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider + GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider, + ContentService $contentService ) { $this->contentTypeService = $contentTypeService; $this->userService = $userService; @@ -71,6 +75,7 @@ public function __construct( $this->permissionResolver = $permissionResolver; $this->userLanguagePreferenceProvider = $userLanguagePreferenceProvider; $this->groupedContentFormFieldsProvider = $groupedContentFormFieldsProvider; + $this->contentService = $contentService; } /** @@ -114,6 +119,7 @@ public function createAction( $form = $this->createForm(UserCreateType::class, $data, [ 'languageCode' => $language->languageCode, 'mainLanguageCode' => $language->languageCode, + 'struct' => $data, ]); $form->handleRequest($request); @@ -152,6 +158,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,9 +199,11 @@ public function editAction( $userUpdate, [ 'location' => $location, + 'content' => $this->contentService->loadContent($contentId), 'languageCode' => $language, 'mainLanguageCode' => $user->contentInfo->mainLanguageCode, - ] + 'struct' => $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/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/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/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/StructFieldOptionsEvent.php b/src/lib/Event/StructFieldOptionsEvent.php new file mode 100644 index 00000000..b3a15e8a --- /dev/null +++ b/src/lib/Event/StructFieldOptionsEvent.php @@ -0,0 +1,75 @@ + */ + protected array $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; + } + + /** + * @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 new file mode 100644 index 00000000..7fa212bf --- /dev/null +++ b/src/lib/Event/UserCreateFieldOptionsEvent.php @@ -0,0 +1,34 @@ +userCreateStruct = $userCreateStruct; + + parent::__construct($parentForm, $fieldData, $options); + } + + public function getUserCreateStruct(): UserCreateStruct + { + return $this->userCreateStruct; + } +} diff --git a/src/lib/Event/UserUpdateFieldOptionsEvent.php b/src/lib/Event/UserUpdateFieldOptionsEvent.php new file mode 100644 index 00000000..55a32c5b --- /dev/null +++ b/src/lib/Event/UserUpdateFieldOptionsEvent.php @@ -0,0 +1,44 @@ +content = $content; + $this->userUpdateStruct = $userUpdateStruct; + + parent::__construct($parentForm, $fieldData, $options); + } + + public function getContent(): Content + { + return $this->content; + } + + public function getUserUpdateStruct(): UserUpdateStruct + { + return $this->userUpdateStruct; + } +} diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index cf2fdfce..515f848c 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\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; 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; /** @@ -44,7 +49,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'content' => $options['content'] ?? null, 'contentCreateStruct' => $options['contentCreateStruct'] ?? null, 'contentUpdateStruct' => $options['contentUpdateStruct'] ?? null, + 'struct' => $options['struct'], ], + 'translation_domain' => 'ibexa_content_forms_content', ]) ->add('redirectUrlAfterPublish', HiddenType::class, [ 'required' => false, @@ -61,8 +68,45 @@ 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']); + ->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, + ]) + ->setAllowedTypes( + 'struct', + [ + 'null', + ContentCreateStruct::class, + ContentUpdateStruct::class, + UserCreateStruct::class, + UserUpdateStruct::class, + ], + ) + ->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 b4a17f3e..71b52b06 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; @@ -43,6 +47,7 @@ public function getBlockPrefix() public function configureOptions(OptionsResolver $resolver) { $resolver + ->setRequired(['languageCode', 'mainLanguageCode', 'struct']) ->setDefaults([ 'content' => null, 'location' => null, @@ -51,7 +56,30 @@ public function configureOptions(OptionsResolver $resolver) 'data_class' => FieldData::class, 'translation_domain' => 'ibexa_content_forms_content', ]) - ->setRequired(['languageCode', 'mainLanguageCode']); + ->setAllowedTypes( + 'struct', + [ + 'null', + ContentCreateStruct::class, + ContentUpdateStruct::class, + UserCreateStruct::class, + UserUpdateStruct::class, + ], + ) + ->setAllowedTypes('contentCreateStruct', ['null', ContentCreateStruct::class]) + ->setAllowedTypes('contentUpdateStruct', ['null', ContentUpdateStruct::class]) + ->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 4873364b..9f53e41d 100644 --- a/src/lib/Form/Type/Content/FieldCollectionType.php +++ b/src/lib/Form/Type/Content/FieldCollectionType.php @@ -11,10 +11,19 @@ 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 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; use Symfony\Component\Form\FormEvents; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class FieldCollectionType extends CollectionType @@ -43,54 +52,151 @@ 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); } }); } - private function isContentCreate(array $entryOptions): bool + public function configureOptions(OptionsResolver $resolver): void { - return !empty($entryOptions['contentCreateStruct']); + parent::configureOptions($resolver); + + $resolver->setDefault('translation_domain', 'ibexa_content_forms_content'); } - private function isContentUpdate(array $entryOptions): bool - { - return !empty($entryOptions['content']) && !empty($entryOptions['contentUpdateStruct']); + /** + * @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(); + } + + /** + * @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 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 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(); + } + + /** + * @param array $entryOptions + * + * @return array + */ + private function dispatchFieldOptionsEvent( + FieldData $entryData, + array $entryOptions, + FormInterface $form + ): array { + if (!isset($entryOptions['struct'])) { + 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; + } } } diff --git a/src/lib/Form/Type/User/UserCreateType.php b/src/lib/Form/Type/User/UserCreateType.php index 3d9f8b44..2fd75bcc 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; @@ -43,14 +44,16 @@ 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 + ->setRequired('struct') ->setDefaults([ '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 5b3af50d..3fcd4cf6 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; @@ -43,15 +44,18 @@ 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 + ->setRequired('struct') ->setDefaults([ 'location' => null, + 'content' => null, 'data_class' => UserUpdateData::class, 'intent' => 'update', 'translation_domain' => 'ibexa_content_forms_user', - ]); + ]) + ->setAllowedTypes('struct', UserUpdateStruct::class); } }