From 978a1651bac3faf5e91ddba327bf39aeb6a4cb63 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:28:59 +0200 Subject: Adding upstream version 0.10.0. Signed-off-by: Daniel Baumann --- .../Web/Forms/Decorator/CompatDecorator.php | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 library/Reporting/Web/Forms/Decorator/CompatDecorator.php (limited to 'library/Reporting/Web/Forms/Decorator/CompatDecorator.php') diff --git a/library/Reporting/Web/Forms/Decorator/CompatDecorator.php b/library/Reporting/Web/Forms/Decorator/CompatDecorator.php new file mode 100644 index 0000000..b2eb536 --- /dev/null +++ b/library/Reporting/Web/Forms/Decorator/CompatDecorator.php @@ -0,0 +1,63 @@ +getAttributes()->has('id')) { + $checkbox->setAttribute('id', base64_encode(random_bytes(8))); + } + + $checkbox->getAttributes()->add('class', 'sr-only'); + + $classes = ['toggle-switch']; + if ($checkbox->getAttributes()->get('disabled')->getValue()) { + $classes[] = 'disabled'; + } + + return [ + $checkbox, + new HtmlElement('label', Attributes::create([ + 'class' => $classes, + 'aria-hidden' => 'true', + 'for' => $checkbox->getAttributes()->get('id')->getValue() + ]), new HtmlElement('span', Attributes::create(['class' => 'toggle-slider']))) + ]; + } + + protected function assembleElementCompat() + { + if ($this->formElement instanceof CheckboxElement) { + return $this->createCheckboxCompat($this->formElement); + } + + return $this->formElement; + } + + protected function assemble() + { + if (version_compare(Version::VERSION, '2.9.0', '>=')) { + parent::assemble(); + return; + } + + if ($this->formElement->hasBeenValidated() && ! $this->formElement->isValid()) { + $this->getAttributes()->add('class', 'has-error'); + } + + $this->add(array_filter([ + $this->assembleLabel(), + $this->assembleElementCompat(), + $this->assembleDescription(), + $this->assembleErrors() + ])); + } +} -- cgit v1.2.3