Skip to content

Commit

Permalink
IBX-7935: Handled User-related structs in FieldCollectionType dispa…
Browse files Browse the repository at this point in the history
…tcher
  • Loading branch information
barw4 committed Mar 14, 2024
1 parent 7eb6c5b commit 954725a
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 42 deletions.
12 changes: 11 additions & 1 deletion src/bundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -71,6 +76,7 @@ public function __construct(
$this->permissionResolver = $permissionResolver;
$this->userLanguagePreferenceProvider = $userLanguagePreferenceProvider;
$this->groupedContentFormFieldsProvider = $groupedContentFormFieldsProvider;
$this->contentService = $contentService;
}

/**
Expand Down Expand Up @@ -114,6 +120,7 @@ public function createAction(
$form = $this->createForm(UserCreateType::class, $data, [
'languageCode' => $language->languageCode,
'mainLanguageCode' => $language->languageCode,
'userCreateStruct' => $data,
]);
$form->handleRequest($request);

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 9 additions & 8 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
10 changes: 10 additions & 0 deletions src/lib/Event/ContentFormEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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');
82 changes: 82 additions & 0 deletions src/lib/Event/UserCreateFieldOptionsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\ContentForms\Event;

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
{
/** @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<string, mixed> */
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<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
}

/**
* @param array<string, mixed> $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;
}
}
98 changes: 98 additions & 0 deletions src/lib/Event/UserUpdateFieldOptionsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\ContentForms\Event;

use Ibexa\Contracts\ContentForms\Data\Content\FieldData;
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
{
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content */
private $content;

/** @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<string, mixed> */
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<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
}

/**
* @param array<string, mixed> $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;
}
}
2 changes: 2 additions & 0 deletions src/lib/Form/Type/Content/BaseContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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, [
Expand Down
2 changes: 2 additions & 0 deletions src/lib/Form/Type/Content/ContentFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => 'ezplatform_content_forms_content',
])
Expand Down
Loading

0 comments on commit 954725a

Please sign in to comment.