From 7daea32ddc381620bee1743b134638f61fa64cde Mon Sep 17 00:00:00 2001 From: Richard Klees Date: Thu, 16 May 2024 12:15:43 +0200 Subject: [PATCH] UI: fix backwards compatibility for Data/Table backport The method isClientSideValueOk changing from protected to public made plugins break that implemented their own inputs. When switching back the method to public, unit tests fail, indicating that we cross class hierarchies when calling the method. This was due to the fact that we indeed had two different methods isClientSideValueOk, one from the original input hierarchy, one from a trait for groups. These are reconciled now and thus the method can be protected again. --- src/UI/Implementation/Component/Input/Field/Checkbox.php | 2 +- src/UI/Implementation/Component/Input/Field/DateTime.php | 2 +- src/UI/Implementation/Component/Input/Field/Duration.php | 2 +- src/UI/Implementation/Component/Input/Field/File.php | 2 +- src/UI/Implementation/Component/Input/Field/Group.php | 6 ++++++ src/UI/Implementation/Component/Input/Field/Hidden.php | 2 +- src/UI/Implementation/Component/Input/Field/Link.php | 2 +- src/UI/Implementation/Component/Input/Field/MultiSelect.php | 2 +- src/UI/Implementation/Component/Input/Field/Numeric.php | 2 +- .../Implementation/Component/Input/Field/OptionalGroup.php | 2 +- src/UI/Implementation/Component/Input/Field/Password.php | 2 +- src/UI/Implementation/Component/Input/Field/Radio.php | 2 +- src/UI/Implementation/Component/Input/Field/Select.php | 2 +- .../Component/Input/Field/SwitchableGroup.php | 2 +- src/UI/Implementation/Component/Input/Field/Tag.php | 2 +- src/UI/Implementation/Component/Input/Field/Text.php | 2 +- src/UI/Implementation/Component/Input/Field/Textarea.php | 2 +- src/UI/Implementation/Component/Input/Field/Url.php | 2 +- src/UI/Implementation/Component/Input/Group.php | 6 ++++-- src/UI/Implementation/Component/Input/Input.php | 2 +- .../Component/Input/ViewControl/FieldSelection.php | 2 +- src/UI/Implementation/Component/Input/ViewControl/Group.php | 6 ++++++ .../Component/Input/ViewControl/GroupDecorator.php | 2 +- 23 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/UI/Implementation/Component/Input/Field/Checkbox.php b/src/UI/Implementation/Component/Input/Field/Checkbox.php index 32cba0be0840..55a899950db0 100644 --- a/src/UI/Implementation/Component/Input/Field/Checkbox.php +++ b/src/UI/Implementation/Component/Input/Field/Checkbox.php @@ -51,7 +51,7 @@ protected function getConstraintForRequirement(): ?Constraint /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { if ($value == "checked" || $value === "" || is_bool($value)) { return true; diff --git a/src/UI/Implementation/Component/Input/Field/DateTime.php b/src/UI/Implementation/Component/Input/Field/DateTime.php index 4123dcb58e9f..291ff7c97d3f 100644 --- a/src/UI/Implementation/Component/Input/Field/DateTime.php +++ b/src/UI/Implementation/Component/Input/Field/DateTime.php @@ -174,7 +174,7 @@ public function getTimeOnly(): bool return $this->with_time_only; } - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return is_string($value); } diff --git a/src/UI/Implementation/Component/Input/Field/Duration.php b/src/UI/Implementation/Component/Input/Field/Duration.php index c63afaf02c2f..170dc08183da 100644 --- a/src/UI/Implementation/Component/Input/Field/Duration.php +++ b/src/UI/Implementation/Component/Input/Field/Duration.php @@ -276,7 +276,7 @@ public function getTimezone(): ?string /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return true; } diff --git a/src/UI/Implementation/Component/Input/Field/File.php b/src/UI/Implementation/Component/Input/Field/File.php index b5ca9f9dc9db..67870472b297 100644 --- a/src/UI/Implementation/Component/Input/Field/File.php +++ b/src/UI/Implementation/Component/Input/Field/File.php @@ -195,7 +195,7 @@ function ($txt, $value) { ); } - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { if (!is_array($value)) { return false; diff --git a/src/UI/Implementation/Component/Input/Field/Group.php b/src/UI/Implementation/Component/Input/Field/Group.php index dc0f7cb4a6ed..01ad9482f660 100644 --- a/src/UI/Implementation/Component/Input/Field/Group.php +++ b/src/UI/Implementation/Component/Input/Field/Group.php @@ -154,4 +154,10 @@ protected function getDataFactory(): DataFactory { return $this->data_factory; } + + /** ATTENTION: @see GroupInternals::_isClientSideValueOk() */ + protected function isClientSideValueOk($value): bool + { + return $this->_isClientSideValueOk($value); + } } diff --git a/src/UI/Implementation/Component/Input/Field/Hidden.php b/src/UI/Implementation/Component/Input/Field/Hidden.php index ed95cd026e6b..2a0b4316d5da 100644 --- a/src/UI/Implementation/Component/Input/Field/Hidden.php +++ b/src/UI/Implementation/Component/Input/Field/Hidden.php @@ -46,7 +46,7 @@ protected function getConstraintForRequirement(): ?Constraint return null; } - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return true; } diff --git a/src/UI/Implementation/Component/Input/Field/Link.php b/src/UI/Implementation/Component/Input/Field/Link.php index 1f3d62848ec1..207a5d9068c5 100644 --- a/src/UI/Implementation/Component/Input/Field/Link.php +++ b/src/UI/Implementation/Component/Input/Field/Link.php @@ -85,7 +85,7 @@ protected function addTransformation(): void /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return true; } diff --git a/src/UI/Implementation/Component/Input/Field/MultiSelect.php b/src/UI/Implementation/Component/Input/Field/MultiSelect.php index 018a9d77d1ef..531fd32761af 100644 --- a/src/UI/Implementation/Component/Input/Field/MultiSelect.php +++ b/src/UI/Implementation/Component/Input/Field/MultiSelect.php @@ -61,7 +61,7 @@ public function getOptions(): array /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { if (is_null($value)) { return true; diff --git a/src/UI/Implementation/Component/Input/Field/Numeric.php b/src/UI/Implementation/Component/Input/Field/Numeric.php index d65479726886..5075bada2a24 100644 --- a/src/UI/Implementation/Component/Input/Field/Numeric.php +++ b/src/UI/Implementation/Component/Input/Field/Numeric.php @@ -57,7 +57,7 @@ public function __construct( /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return is_numeric($value) || $value === "" || $value === null; } diff --git a/src/UI/Implementation/Component/Input/Field/OptionalGroup.php b/src/UI/Implementation/Component/Input/Field/OptionalGroup.php index 1760cda1c7b6..d34a7121367e 100644 --- a/src/UI/Implementation/Component/Input/Field/OptionalGroup.php +++ b/src/UI/Implementation/Component/Input/Field/OptionalGroup.php @@ -51,7 +51,7 @@ protected function getConstraintForRequirement(): ?Constraint /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { if ($value === null) { return true; diff --git a/src/UI/Implementation/Component/Input/Field/Password.php b/src/UI/Implementation/Component/Input/Field/Password.php index aed9289de75b..41d9fb6dae59 100644 --- a/src/UI/Implementation/Component/Input/Field/Password.php +++ b/src/UI/Implementation/Component/Input/Field/Password.php @@ -61,7 +61,7 @@ public function __construct( /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return is_string($value); } diff --git a/src/UI/Implementation/Component/Input/Field/Radio.php b/src/UI/Implementation/Component/Input/Field/Radio.php index 813917dbe4ad..c29d46f8beb9 100644 --- a/src/UI/Implementation/Component/Input/Field/Radio.php +++ b/src/UI/Implementation/Component/Input/Field/Radio.php @@ -49,7 +49,7 @@ class Radio extends FormInput implements C\Input\Field\Radio /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return ($value === '' || array_key_exists($value, $this->getOptions())); } diff --git a/src/UI/Implementation/Component/Input/Field/Select.php b/src/UI/Implementation/Component/Input/Field/Select.php index 990f1859c835..6ad40cde7527 100644 --- a/src/UI/Implementation/Component/Input/Field/Select.php +++ b/src/UI/Implementation/Component/Input/Field/Select.php @@ -61,7 +61,7 @@ public function getOptions(): array /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return in_array($value, array_keys($this->options)) || $value == ""; } diff --git a/src/UI/Implementation/Component/Input/Field/SwitchableGroup.php b/src/UI/Implementation/Component/Input/Field/SwitchableGroup.php index d3fd342329b6..75d8e2f029a7 100644 --- a/src/UI/Implementation/Component/Input/Field/SwitchableGroup.php +++ b/src/UI/Implementation/Component/Input/Field/SwitchableGroup.php @@ -68,7 +68,7 @@ protected function getConstraintForRequirement(): ?Constraint /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { if (!is_string($value) && !is_int($value)) { return false; diff --git a/src/UI/Implementation/Component/Input/Field/Tag.php b/src/UI/Implementation/Component/Input/Field/Tag.php index 5421500b7693..5773e2e67cba 100644 --- a/src/UI/Implementation/Component/Input/Field/Tag.php +++ b/src/UI/Implementation/Component/Input/Field/Tag.php @@ -132,7 +132,7 @@ protected function getConstraintForRequirement(): ?Constraint /** * @inheritDoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { if ($this->getMaxTags() > 0) { $max_tags = $this->getMaxTags(); diff --git a/src/UI/Implementation/Component/Input/Field/Text.php b/src/UI/Implementation/Component/Input/Field/Text.php index 48e89d85ba47..cad63383e034 100644 --- a/src/UI/Implementation/Component/Input/Field/Text.php +++ b/src/UI/Implementation/Component/Input/Field/Text.php @@ -70,7 +70,7 @@ public function getMaxLength(): ?int /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { if (!is_string($value)) { return false; diff --git a/src/UI/Implementation/Component/Input/Field/Textarea.php b/src/UI/Implementation/Component/Input/Field/Textarea.php index 0de1bf78f4bd..e78802b580b8 100644 --- a/src/UI/Implementation/Component/Input/Field/Textarea.php +++ b/src/UI/Implementation/Component/Input/Field/Textarea.php @@ -103,7 +103,7 @@ public function getMinLimit(): ?int /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return is_string($value); } diff --git a/src/UI/Implementation/Component/Input/Field/Url.php b/src/UI/Implementation/Component/Input/Field/Url.php index f5d53abcb584..e6a66d300215 100644 --- a/src/UI/Implementation/Component/Input/Field/Url.php +++ b/src/UI/Implementation/Component/Input/Field/Url.php @@ -97,7 +97,7 @@ public static function getURIChecker(): Closure /** * @inheritdoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { if (is_string($value) && trim($value) === "") { return true; diff --git a/src/UI/Implementation/Component/Input/Group.php b/src/UI/Implementation/Component/Input/Group.php index d0b650b49e42..4697ca20efbf 100644 --- a/src/UI/Implementation/Component/Input/Group.php +++ b/src/UI/Implementation/Component/Input/Group.php @@ -121,9 +121,11 @@ protected function nameInputs(NameSource $source, string $parent_name): array } /** - * @inheritdoc + * ATTENTION: This is not the same as @see Input::isClientSideValueOk, + * even if it had the same name. These are different symbols, as this trait + * is not in the hierarchy that defines the original isClientSideValueOk. */ - public function isClientSideValueOk($value): bool + protected function _isClientSideValueOk($value): bool { if (!is_array($value)) { return false; diff --git a/src/UI/Implementation/Component/Input/Input.php b/src/UI/Implementation/Component/Input/Input.php index 53d1fdfb05b0..93b489b19dfd 100644 --- a/src/UI/Implementation/Component/Input/Input.php +++ b/src/UI/Implementation/Component/Input/Input.php @@ -116,7 +116,7 @@ public function withValue($value): self * * @param mixed $value */ - abstract public function isClientSideValueOk($value): bool; + abstract protected function isClientSideValueOk($value): bool; /** * The error of the input as used in HTML. diff --git a/src/UI/Implementation/Component/Input/ViewControl/FieldSelection.php b/src/UI/Implementation/Component/Input/ViewControl/FieldSelection.php index 5ba225879339..0c017a6ad746 100644 --- a/src/UI/Implementation/Component/Input/ViewControl/FieldSelection.php +++ b/src/UI/Implementation/Component/Input/ViewControl/FieldSelection.php @@ -45,7 +45,7 @@ public function __construct( $this->internal_selection_signal = $signal_generator->create(); } - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return is_null($value) || is_array($value); } diff --git a/src/UI/Implementation/Component/Input/ViewControl/Group.php b/src/UI/Implementation/Component/Input/ViewControl/Group.php index e941f804d14b..1e659793a0cd 100644 --- a/src/UI/Implementation/Component/Input/ViewControl/Group.php +++ b/src/UI/Implementation/Component/Input/ViewControl/Group.php @@ -98,4 +98,10 @@ protected function getDataFactory(): DataFactory { return $this->data_factory; } + + /** ATTENTION: @see GroupInternals::_isClientSideValueOk() */ + protected function isClientSideValueOk($value): bool + { + return $this->_isClientSideValueOk($value); + } } diff --git a/src/UI/Implementation/Component/Input/ViewControl/GroupDecorator.php b/src/UI/Implementation/Component/Input/ViewControl/GroupDecorator.php index c534c4dc1a93..7d73870aa72e 100644 --- a/src/UI/Implementation/Component/Input/ViewControl/GroupDecorator.php +++ b/src/UI/Implementation/Component/Input/ViewControl/GroupDecorator.php @@ -92,7 +92,7 @@ public function getContent(): Result /** * @inheritDoc */ - public function isClientSideValueOk($value): bool + protected function isClientSideValueOk($value): bool { return $this->input_group->isClientSideValueOk($value); }