From 4ce65d59ca91871cfd126497158200a818720bce Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:30:08 +0200 Subject: Adding upstream version 0.13.1. Signed-off-by: Daniel Baumann --- .../web/src/FormDecorator/IcingaFormDecorator.php | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 vendor/ipl/web/src/FormDecorator/IcingaFormDecorator.php (limited to 'vendor/ipl/web/src/FormDecorator') diff --git a/vendor/ipl/web/src/FormDecorator/IcingaFormDecorator.php b/vendor/ipl/web/src/FormDecorator/IcingaFormDecorator.php new file mode 100644 index 0000000..f038931 --- /dev/null +++ b/vendor/ipl/web/src/FormDecorator/IcingaFormDecorator.php @@ -0,0 +1,123 @@ +formElement instanceof FormSubmitElement) { + $this->formElement->getAttributes()->add('class', 'btn-primary'); + } + + $element = parent::assembleElement(); + + if ($element instanceof CheckboxElement) { + return $this->createCheckbox($element); + } + + return $element; + } + + protected function createCheckbox(CheckboxElement $checkbox) + { + if (! $checkbox->getAttributes()->has('id')) { + $checkbox->setAttribute( + 'id', + $checkbox->getName() . '_' . Window::getInstance()->getContainerId() + ); + } + + $checkbox->getAttributes()->add('class', 'sr-only'); + + $classes = ['toggle-switch']; + if ($checkbox->getAttributes()->get('disabled')->getValue()) { + $classes[] = 'disabled'; + } + + $document = new HtmlDocument(); + $document->addHtml( + $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'])) + ) + ); + + $checkbox->prependWrapper($document); + + return $checkbox; + } + + protected function assembleLabel() + { + $label = parent::assembleLabel(); + if (! $this->formElement instanceof FieldsetElement) { + if ($label !== null) { + $label->addWrapper(new HtmlElement('div', Attributes::create(['class' => 'control-label-group']))); + } elseif (! $this->formElement instanceof FormSubmitElement) { + $label = new HtmlElement( + 'div', + Attributes::create(['class' => 'control-label-group']), + HtmlString::create(' ') + ); + } + } + + return $label; + } + + protected function assembleDescription() + { + if ($this->formElement instanceof FieldsetElement) { + return parent::assembleDescription(); + } + + if (($description = $this->formElement->getDescription()) !== null) { + $iconAttributes = [ + 'class' => 'control-info', + 'role' => 'image', + 'title' => $description + ]; + + $describedBy = null; + if ($this->formElement->getAttributes()->has('id')) { + $iconAttributes['aria-hidden'] = 'true'; + + $descriptionId = 'desc_' . $this->formElement->getAttributes()->get('id')->getValue(); + $describedBy = new HtmlElement('span', Attributes::create([ + 'id' => $descriptionId, + 'class' => 'sr-only' + ]), Text::create($description)); + + $this->formElement->getAttributes()->set('aria-describedby', $descriptionId); + } + + return [ + new Icon('info-circle', $iconAttributes), + $describedBy + ]; + } + } +} -- cgit v1.2.3