diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 0dc607412..e97190d66 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -126,6 +126,13 @@ class Form extends Zend_Form */ protected $requiredCue = '*'; + /** + * The descriptions of this form + * + * @var array + */ + protected $descriptions; + /** * Authentication manager * @@ -436,6 +443,49 @@ class Form extends Zend_Form return $this->requiredCue; } + /** + * Set the descriptions for this form + * + * @param array $descriptions + * + * @return Form + */ + public function setDescriptions(array $descriptions) + { + $this->descriptions = $descriptions; + return $this; + } + + /** + * Add a description for this form + * + * If $description is an array the second value should be + * an array as well containing additional HTML properties. + * + * @param string|array $description + * + * @return Form + */ + public function addDescription($description) + { + $this->descriptions[] = $description; + return $this; + } + + /** + * Return the descriptions of this form + * + * @return array + */ + public function getDescriptions() + { + if ($this->descriptions === null) { + return array(); + } + + return $this->descriptions; + } + /** * Create this form * @@ -860,6 +910,7 @@ class Form extends Zend_Form )); } else { $this->addDecorator('FormErrors', array('onlyCustomFormErrors' => true)) + ->addDecorator('FormDescriptions') ->addDecorator('FormElements') //->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')) ->addDecorator('Form'); diff --git a/library/Icinga/Web/Form/Decorator/FormDescriptions.php b/library/Icinga/Web/Form/Decorator/FormDescriptions.php new file mode 100644 index 000000000..936708e62 --- /dev/null +++ b/library/Icinga/Web/Form/Decorator/FormDescriptions.php @@ -0,0 +1,55 @@ +getElement(); + if (! $form instanceof Form) { + return $content; + } + + $view = $form->getView(); + if ($view === null) { + return $content; + } + + $descriptions = $form->getDescriptions(); + if (empty($descriptions)) { + return $content; + } + + $html = '