From 7534cbad20d2ba354fb37ab0f1fa38a5552e3364 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 15 Mar 2024 11:48:06 +0100 Subject: [PATCH] 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; - } }