QuickForm: optimize runtime order

This commit is contained in:
Thomas Gelf 2016-05-24 20:25:16 +02:00
parent 81dcfb4f7e
commit d01194a7b4

View File

@ -84,7 +84,9 @@ abstract class QuickForm extends QuickBaseForm
protected function addSubmitButtonIfSet() protected function addSubmitButtonIfSet()
{ {
if (false !== ($label = $this->getSubmitLabel())) { if (false !== ($label = $this->getSubmitLabel())) {
$el = $this->createElement('submit', $label)->setLabel($label)->setDecorators(array('ViewHelper')); $el = $this->createElement('submit', $label)
->setLabel($label)
->setDecorators(array('ViewHelper'));
$this->submitButtonName = $el->getName(); $this->submitButtonName = $el->getName();
$this->addElement($el); $this->addElement($el);
@ -296,12 +298,16 @@ abstract class QuickForm extends QuickBaseForm
public function handleRequest(Request $request = null) public function handleRequest(Request $request = null)
{ {
if ($request !== null) { if ($request === null) {
$request = $this->getRequest();
} else {
$this->setRequest($request); $this->setRequest($request);
} }
$this->prepareElements();
if ($this->hasBeenSent()) { if ($this->hasBeenSent()) {
$post = $this->getRequest()->getPost(); $post = $request->getPost();
if ($this->hasBeenSubmitted()) { if ($this->hasBeenSubmitted()) {
$this->beforeValidation($post); $this->beforeValidation($post);
if ($this->isValid($post)) { if ($this->isValid($post)) {
@ -416,7 +422,13 @@ abstract class QuickForm extends QuickBaseForm
public function hasBeenSent() public function hasBeenSent()
{ {
if ($this->hasBeenSent === null) { if ($this->hasBeenSent === null) {
$req = $this->getRequest();
if ($this->request === null) {
$req = Icinga::app()->getFrontController()->getRequest();
} else {
$req = $this->request;
}
if ($req->isPost()) { if ($req->isPost()) {
$post = $req->getPost(); $post = $req->getPost();
$this->hasBeenSent = array_key_exists(self::ID, $post) && $this->hasBeenSent = array_key_exists(self::ID, $post) &&