From aa1e6f995948bc6d08a752df732d5c7f12d088be Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 15 Mar 2024 11:56:12 +0100 Subject: [PATCH] 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;