diff --git a/library/Director/Web/Form/FormLoader.php b/library/Director/Web/Form/FormLoader.php index e5d21281..50d688ff 100644 --- a/library/Director/Web/Form/FormLoader.php +++ b/library/Director/Web/Form/FormLoader.php @@ -24,7 +24,12 @@ class FormLoader if (file_exists($file)) { require_once($file); $class = $ns . $class; - return new $class(); + $options = array(); + if ($module !== null) { + $options['icingaModule'] = $module; + } + + return new $class($options); } } throw new ProgrammingError(sprintf('Cannot load %s (%s), no such form', $name, $file)); diff --git a/library/Director/Web/Form/QuickForm.php b/library/Director/Web/Form/QuickForm.php index 20d54dc9..80ac2643 100644 --- a/library/Director/Web/Form/QuickForm.php +++ b/library/Director/Web/Form/QuickForm.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\Web\Form; use Icinga\Application\Icinga; +use Icinga\Application\Modules\Module; use Icinga\Web\Notification; use Icinga\Web\Request; use Icinga\Web\Url; @@ -48,8 +49,18 @@ abstract class QuickForm extends Zend_Form protected $submitLabel; + /** + * The Icinga module this form belongs to. Usually only set if the + * form is initialized through the FormLoader + */ + protected $icingaModule; + public function __construct($options = null) { + if (array_key_exists('icingaModule', $options)) { + $this->icingaModule = $options['icingaModule']; + unset($options['icingaModule']); + } parent::__construct($options); $this->setMethod('post'); $this->setAction(Url::fromRequest()); @@ -89,6 +100,15 @@ abstract class QuickForm extends Zend_Form return $this; } + protected function loadForm($name, Module $module = null) + { + if ($module === null) { + $module = $this->icingaModule; + } + + return FormLoader::load($name, $module); + } + public function regenerateCsrfToken() { if (! $element = $this->getElement(self::CSRF)) { @@ -137,6 +157,12 @@ abstract class QuickForm extends Zend_Form return parent::setAction((string) $action); } + public function setIcingaModule(Module $module) + { + $this->icingaModule = $module; + return $this; + } + public function hasBeenSubmitted() { if ($this->hasBeenSubmitted === null) {