From bc9da11e3f6587f43b72712c34f77304adb821b5 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Wed, 12 Jul 2023 10:17:48 +0200 Subject: [PATCH] Drop `CompatDecorator` & use form default decorator instead --- .../Web/Forms/Decorator/CompatDecorator.php | 65 ------------------- library/Reporting/Web/Forms/ReportForm.php | 3 - library/Reporting/Web/Forms/SendForm.php | 3 - library/Reporting/Web/Forms/TemplateForm.php | 3 - 4 files changed, 74 deletions(-) delete mode 100644 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 deleted file mode 100644 index 39b443f3..00000000 --- a/library/Reporting/Web/Forms/Decorator/CompatDecorator.php +++ /dev/null @@ -1,65 +0,0 @@ -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->hasMessages()) { - $this->getAttributes()->add('class', 'has-error'); - } - - $this->add(array_filter([ - $this->assembleLabel(), - $this->assembleElementCompat(), - $this->assembleDescription(), - $this->assembleErrors() - ])); - } -} diff --git a/library/Reporting/Web/Forms/ReportForm.php b/library/Reporting/Web/Forms/ReportForm.php index 031f1cd2..9b6e5c52 100644 --- a/library/Reporting/Web/Forms/ReportForm.php +++ b/library/Reporting/Web/Forms/ReportForm.php @@ -7,7 +7,6 @@ use Icinga\Authentication\Auth; use Icinga\Module\Reporting\Database; use Icinga\Module\Reporting\ProvidedReports; -use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator; use ipl\Html\Contract\FormSubmitElement; use ipl\Html\Form; use ipl\Validator\CallbackValidator; @@ -73,8 +72,6 @@ public function hasBeenSubmitted(): bool protected function assemble() { - $this->setDefaultElementDecorator(new CompatDecorator()); - $this->addElement('text', 'name', [ 'required' => true, 'label' => $this->translate('Name'), diff --git a/library/Reporting/Web/Forms/SendForm.php b/library/Reporting/Web/Forms/SendForm.php index 7e206029..657dff50 100644 --- a/library/Reporting/Web/Forms/SendForm.php +++ b/library/Reporting/Web/Forms/SendForm.php @@ -8,7 +8,6 @@ use Icinga\Module\Reporting\Database; use Icinga\Module\Reporting\ProvidedReports; use Icinga\Module\Reporting\Report; -use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator; use ipl\Web\Compat\CompatForm; class SendForm extends CompatForm @@ -28,8 +27,6 @@ public function setReport(Report $report) protected function assemble() { - $this->setDefaultElementDecorator(new CompatDecorator()); - (new SendMail())->initConfigForm($this, $this->report); $this->addElement('submit', 'submit', [ diff --git a/library/Reporting/Web/Forms/TemplateForm.php b/library/Reporting/Web/Forms/TemplateForm.php index 3509a895..94f742cf 100644 --- a/library/Reporting/Web/Forms/TemplateForm.php +++ b/library/Reporting/Web/Forms/TemplateForm.php @@ -7,7 +7,6 @@ use Exception; use Icinga\Authentication\Auth; use Icinga\Module\Reporting\Database; -use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator; use ipl\Html\Contract\FormSubmitElement; use ipl\Html\Html; use ipl\Web\Compat\CompatForm; @@ -54,8 +53,6 @@ public function hasBeenSubmitted(): bool protected function assemble() { - $this->setDefaultElementDecorator(new CompatDecorator()); - $this->setAttribute('enctype', 'multipart/form-data'); $this->add(Html::tag('h2', 'Template Settings'));