Don't override Zend's Checkbox for our toggle switch
This commit is contained in:
parent
41ee36c7e6
commit
c49f5d6a0f
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2019 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Form\Element;
|
||||
|
||||
class Checkbox extends \Zend_Form_Element_Checkbox
|
||||
{
|
||||
public function loadDefaultDecorators()
|
||||
{
|
||||
parent::loadDefaultDecorators();
|
||||
|
||||
if (! $this->loadDefaultDecoratorsIsDisabled()) {
|
||||
$class = 'toggle-switch';
|
||||
if ($this->getAttrib('disabled')) {
|
||||
$class .= ' disabled';
|
||||
}
|
||||
$currentDecorators = $this->getDecorators();
|
||||
$pos = array_search('Zend_Form_Decorator_ViewHelper', array_keys($currentDecorators), true);
|
||||
$decorators = array_slice($currentDecorators, 0, $pos);
|
||||
$decorators += [
|
||||
'ToggleSwitchOpen' => [
|
||||
['ToggleSwitchOpen' => 'HtmlTag'],
|
||||
['tag' => 'label', 'class' => $class, 'openOnly' => true, 'placement' => 'append']
|
||||
]
|
||||
];
|
||||
$decorators += array_slice($currentDecorators, $pos, 1);
|
||||
$decorators += [
|
||||
'ToggleSlider' => [
|
||||
['ToggleSlider' => 'HtmlTag'],
|
||||
['tag' => 'span', 'class' => 'toggle-slider', 'placement' => 'append']
|
||||
],
|
||||
'ToggleSwitchClose' => [
|
||||
['ToggleSwitchClose' => 'HtmlTag'],
|
||||
['tag' => 'label', 'closeOnly' => true, 'placement' => 'append']
|
||||
]
|
||||
];
|
||||
$decorators += array_slice($currentDecorators, $pos + 1);
|
||||
$this->setDecorators($decorators);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -76,10 +76,8 @@ class Zend_View_Helper_FormCheckbox extends Zend_View_Helper_FormElement
|
|||
|
||||
// is the element disabled?
|
||||
$disabled = '';
|
||||
$classDisabled = '';
|
||||
if ($disable) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
$classDisabled = ' disabled';
|
||||
}
|
||||
|
||||
// build the element
|
||||
|
@ -94,17 +92,14 @@ class Zend_View_Helper_FormCheckbox extends Zend_View_Helper_FormElement
|
|||
unset($attribs['disableHidden']);
|
||||
}
|
||||
|
||||
$xhtml .= '<label class="toggle-switch' . $classDisabled .'">'
|
||||
. '<input type="checkbox"'
|
||||
$xhtml .= '<input type="checkbox"'
|
||||
. ' name="' . $this->view->escape($name) . '"'
|
||||
. ' id="' . $this->view->escape($id) . '"'
|
||||
. ' value="' . $this->view->escape($checkedOptions['checkedValue']) . '"'
|
||||
. $checkedOptions['checkedString']
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. $this->getClosingBracket()
|
||||
. '<span class="toggle-slider"></span>'
|
||||
. '</label>';
|
||||
. $this->getClosingBracket();
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue