QuickForm/FormLoader: add helper for subforms
This commit is contained in:
parent
6730ac7447
commit
61795ccdcd
|
@ -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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue