From 6be51d15654885ab100c8f626cc72bd2a14c7065 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 13 Nov 2014 14:25:51 +0100 Subject: [PATCH] Use Icinga\Web\Form\Element\Button instead of Zend's button Due to a bug in Zend prior to 1.12.2 we need our own button implementation to support earlier versions of the Zend Framework. The side effect is, that this button can also be used as submit button for our forms as isChecked will do its job now properly. --- library/Icinga/Web/Form/Element/Button.php | 81 ++++++++++++++++++++++ library/Icinga/Web/Wizard.php | 76 ++++++++++---------- 2 files changed, 122 insertions(+), 35 deletions(-) create mode 100644 library/Icinga/Web/Form/Element/Button.php diff --git a/library/Icinga/Web/Form/Element/Button.php b/library/Icinga/Web/Form/Element/Button.php new file mode 100644 index 000000000..00da28d10 --- /dev/null +++ b/library/Icinga/Web/Form/Element/Button.php @@ -0,0 +1,81 @@ + $options); + } + + if (!isset($options['ignore'])) { + $options['ignore'] = true; + } + + parent::__construct($spec, $options); + + if ($label = $this->getLabel()) { + // Necessary to get the label shown on the generated HTML + $this->content = $label; + } + } + + /** + * Validate element value (pseudo) + * + * There is no need to reset the value + * + * @param mixed $value Is always ignored + * @param mixed $context Is always ignored + * + * @return bool Returns always TRUE + */ + public function isValid($value, $context = null) + { + return true; + } + + /** + * Has this button been selected? + * + * @return bool + */ + public function isChecked() + { + return $this->getRequest()->getParam($this->getName()) === $this->getValue(); + } + + /** + * Return the current request + * + * @return Request + */ + protected function getRequest() + { + return Icinga::app()->getFrontController()->getRequest(); + } +} diff --git a/library/Icinga/Web/Wizard.php b/library/Icinga/Web/Wizard.php index faf950292..424b46b2c 100644 --- a/library/Icinga/Web/Wizard.php +++ b/library/Icinga/Web/Wizard.php @@ -8,6 +8,7 @@ use LogicException; use InvalidArgumentException; use Icinga\Web\Session\SessionNamespace; use Icinga\Web\Form\Decorator\ElementDoubler; +use Icinga\Web\Form\Element\Button; /** * Container and controller for form based wizards @@ -426,55 +427,60 @@ class Wizard $index = array_search($page, $pages, true); if ($index === 0) { $page->addElement( - 'button', - static::BTN_NEXT, - array( - 'type' => 'submit', - 'value' => $pages[1]->getName(), - 'label' => t('Next'), - 'decorators' => array('ViewHelper') + new Button( + static::BTN_NEXT, + array( + 'type' => 'submit', + 'value' => $pages[1]->getName(), + 'label' => t('Next'), + 'decorators' => array('ViewHelper') + ) ) ); } elseif ($index < count($pages) - 1) { $page->addElement( - 'button', - static::BTN_PREV, - array( - 'type' => 'submit', - 'value' => $pages[$index - 1]->getName(), - 'label' => t('Back'), - 'decorators' => array('ViewHelper') + new Button( + static::BTN_PREV, + array( + 'type' => 'submit', + 'value' => $pages[$index - 1]->getName(), + 'label' => t('Back'), + 'decorators' => array('ViewHelper') + ) ) ); $page->addElement( - 'button', - static::BTN_NEXT, - array( - 'type' => 'submit', - 'value' => $pages[$index + 1]->getName(), - 'label' => t('Next'), - 'decorators' => array('ViewHelper') + new Button( + static::BTN_NEXT, + array( + 'type' => 'submit', + 'value' => $pages[$index + 1]->getName(), + 'label' => t('Next'), + 'decorators' => array('ViewHelper') + ) ) ); } else { $page->addElement( - 'button', - static::BTN_PREV, - array( - 'type' => 'submit', - 'value' => $pages[$index - 1]->getName(), - 'label' => t('Back'), - 'decorators' => array('ViewHelper') + new Button( + static::BTN_PREV, + array( + 'type' => 'submit', + 'value' => $pages[$index - 1]->getName(), + 'label' => t('Back'), + 'decorators' => array('ViewHelper') + ) ) ); $page->addElement( - 'button', - static::BTN_NEXT, - array( - 'type' => 'submit', - 'value' => $page->getName(), - 'label' => t('Finish'), - 'decorators' => array('ViewHelper') + new Button( + static::BTN_NEXT, + array( + 'type' => 'submit', + 'value' => $page->getName(), + 'label' => t('Finish'), + 'decorators' => array('ViewHelper') + ) ) ); }