From 49eea1d33bbaf5d15836c3b9b82d591ce3585fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=A4u=C3=9Fler?= <elias@haeussler.dev> Date: Wed, 27 Apr 2022 11:23:30 +0200 Subject: [PATCH] [TASK] Move form element-related methods out of AbstractRenderable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With #90385, two methods (`setDefaultValue()` and `setProperty()`) were added to AbstractRenderable. Those methods however only relate to form elements and the corresponding FormElementInterface and are not part of the RenderableInterface. All form elements already provide appropriate implementations. In order to separate methods of form elements from methods of generic renderables, the change #90385 has been reverted. Additionally, the implementation logic to call those methods has been separated from AbstractRenderable and re-implemented in the appropriate form elements, namely AbstractFormElement and Section. This is not considered breaking, because all logic is re-implemented in relevant and affected classes. Furthermore, it's not sufficient to provide and implement defaultValue and properties for renderables that do not represent a form element. Resolves: #90400 Related: #90385 Releases: main Change-Id: Id258233337c0e648a1459e537460cd02f96e7f29 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74443 Tested-by: core-ci <typo3@b13.com> Tested-by: Björn Jacob <bjoern.jacob@tritum.de> Tested-by: waldhacker <hello@waldhacker.dev> Reviewed-by: Björn Jacob <bjoern.jacob@tritum.de> Reviewed-by: waldhacker <hello@waldhacker.dev> --- .../FormElements/AbstractFormElement.php | 15 ++++++++++++++ .../Domain/Model/FormElements/Section.php | 11 ++++++++++ .../Model/Renderable/AbstractRenderable.php | 20 ------------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/typo3/sysext/form/Classes/Domain/Model/FormElements/AbstractFormElement.php b/typo3/sysext/form/Classes/Domain/Model/FormElements/AbstractFormElement.php index 6fa1bcfc7696..da183ff66b6f 100644 --- a/typo3/sysext/form/Classes/Domain/Model/FormElements/AbstractFormElement.php +++ b/typo3/sysext/form/Classes/Domain/Model/FormElements/AbstractFormElement.php @@ -98,6 +98,21 @@ abstract class AbstractFormElement extends AbstractRenderable implements FormEle return lcfirst($uniqueIdentifier); } + public function setOptions(array $options, bool $resetValidators = false) + { + if (isset($options['defaultValue'])) { + $this->setDefaultValue($options['defaultValue']); + } + + if (isset($options['properties'])) { + foreach ($options['properties'] as $key => $value) { + $this->setProperty($key, $value); + } + } + + parent::setOptions($options, $resetValidators); + } + /** * Get the default value of the element * diff --git a/typo3/sysext/form/Classes/Domain/Model/FormElements/Section.php b/typo3/sysext/form/Classes/Domain/Model/FormElements/Section.php index 06d8b07e29cc..7a4523f0b15c 100644 --- a/typo3/sysext/form/Classes/Domain/Model/FormElements/Section.php +++ b/typo3/sysext/form/Classes/Domain/Model/FormElements/Section.php @@ -61,6 +61,17 @@ class Section extends AbstractSection implements FormElementInterface } } + public function setOptions(array $options, bool $resetValidators = false) + { + if (isset($options['properties'])) { + foreach ($options['properties'] as $key => $value) { + $this->setProperty($key, $value); + } + } + + parent::setOptions($options, $resetValidators); + } + /** * Returns a unique identifier of this element. * While element identifiers are only unique within one form, diff --git a/typo3/sysext/form/Classes/Domain/Model/Renderable/AbstractRenderable.php b/typo3/sysext/form/Classes/Domain/Model/Renderable/AbstractRenderable.php index ac73611268c9..d88ca28a4201 100644 --- a/typo3/sysext/form/Classes/Domain/Model/Renderable/AbstractRenderable.php +++ b/typo3/sysext/form/Classes/Domain/Model/Renderable/AbstractRenderable.php @@ -144,16 +144,6 @@ abstract class AbstractRenderable implements RenderableInterface, VariableRender $this->setLabel($options['label']); } - if (isset($options['defaultValue'])) { - $this->setDefaultValue($options['defaultValue']); - } - - if (isset($options['properties'])) { - foreach ($options['properties'] as $key => $value) { - $this->setProperty($key, $value); - } - } - if (isset($options['renderingOptions'])) { foreach ($options['renderingOptions'] as $key => $value) { $this->setRenderingOption($key, $value); @@ -414,16 +404,6 @@ abstract class AbstractRenderable implements RenderableInterface, VariableRender $this->label = $label; } - public function setDefaultValue($defaultValue) - { - // todo: this method must either be abstract and implemented in sub classes or get a proper method body. - } - - public function setProperty(string $key, $value) - { - // todo: this method must either be abstract and implemented in sub classes or get a proper method body. - } - /** * Get the templateName name of the renderable * -- GitLab