Skip to content

Commit

Permalink
IBX-7935: Further code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Apr 3, 2024
1 parent 7534cba commit aa1e6f9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 91 deletions.
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;

/** @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');
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');
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Event/UserCreateFieldOptionsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Event/UserUpdateFieldOptionsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit aa1e6f9

Please sign in to comment.