QuickForm: postpone setup() call

This commit is contained in:
Thomas Gelf 2015-07-28 11:37:08 +02:00
parent 570a0ac00a
commit 38501e8e96

View File

@ -49,6 +49,11 @@ abstract class QuickForm extends Zend_Form
protected $submitLabel; protected $submitLabel;
/**
* Whether form elements have already been created
*/
protected $didSetup = false;
/** /**
* The Icinga module this form belongs to. Usually only set if the * The Icinga module this form belongs to. Usually only set if the
* form is initialized through the FormLoader * form is initialized through the FormLoader
@ -66,9 +71,6 @@ abstract class QuickForm extends Zend_Form
$this->setAction(Url::fromRequest()); $this->setAction(Url::fromRequest());
$this->createIdElement(); $this->createIdElement();
$this->regenerateCsrfToken(); $this->regenerateCsrfToken();
$this->setup();
$this->onSetup();
$this->addSubmitButtonIfSet();
} }
protected function addSubmitButtonIfSet() protected function addSubmitButtonIfSet()
@ -197,12 +199,26 @@ abstract class QuickForm extends Zend_Form
{ {
} }
public function prepareElements()
{
if (! $this->didSetup) {
$this->setup();
$this->onSetup();
$this->addSubmitButtonIfSet();
$this->didSetup = true;
}
return $this;
}
public function handleRequest(Request $request = null) public function handleRequest(Request $request = null)
{ {
if ($request !== null) { if ($request !== null) {
$this->request = $request; $this->request = $request;
} }
$this->prepareElements();
if ($this->hasBeenSent()) { if ($this->hasBeenSent()) {
$post = $this->getRequest()->getPost(); $post = $this->getRequest()->getPost();
if ($this->hasBeenSubmitted()) { if ($this->hasBeenSubmitted()) {