Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-7935: Handled User-related structs in FieldCollectionType dispatcher #64

Merged
merged 17 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 */
barw4 marked this conversation as resolved.
Show resolved Hide resolved
private $contentService;
barw4 marked this conversation as resolved.
Show resolved Hide resolved

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
47 changes: 3 additions & 44 deletions src/lib/Event/ContentCreateFieldOptionsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,27 @@
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;
barw4 marked this conversation as resolved.
Show resolved Hide resolved

/** @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,
FieldData $fieldData,
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');
10 changes: 10 additions & 0 deletions src/lib/Event/ContentFormEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
47 changes: 3 additions & 44 deletions src/lib/Event/ContentUpdateFieldOptionsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,15 @@
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;

/** @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,
Expand All @@ -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
Expand All @@ -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');
77 changes: 77 additions & 0 deletions src/lib/Event/StructFieldOptionsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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 Symfony\Component\Form\FormInterface;
use Symfony\Contracts\EventDispatcher\Event;

abstract class StructFieldOptionsEvent extends Event
{
/** @var \Symfony\Component\Form\FormInterface */
barw4 marked this conversation as resolved.
Show resolved Hide resolved
protected $parentForm;
barw4 marked this conversation as resolved.
Show resolved Hide resolved

/** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData */
barw4 marked this conversation as resolved.
Show resolved Hide resolved
protected $fieldData;
barw4 marked this conversation as resolved.
Show resolved Hide resolved

/** @var array<string, mixed> */
protected $options;
barw4 marked this conversation as resolved.
Show resolved Hide resolved

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

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

final class UserCreateFieldOptionsEvent extends StructFieldOptionsEvent
{
/** @var \Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct */
konradoboza marked this conversation as resolved.
Show resolved Hide resolved
private $userCreateStruct;
barw4 marked this conversation as resolved.
Show resolved Hide resolved

public function __construct(
UserCreateStruct $userCreateStruct,
FormInterface $parentForm,
FieldData $fieldData,
array $options
) {
$this->userCreateStruct = $userCreateStruct;

parent::__construct($parentForm, $fieldData, $options);
}

public function getUserCreateStruct(): UserCreateStruct
{
return $this->userCreateStruct;
}
}
Loading
Loading