From: Matthias Schmidt Date: Sun, 24 Feb 2019 16:14:21 +0000 (+0100) Subject: Add flag to signal that form interacts via AJAX requests X-Git-Tag: 5.2.0_Alpha_1~262 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f78f5bb857b5406ee0e152c4af9074632b0c0eac;p=GitHub%2FWoltLab%2FWCF.git Add flag to signal that form interacts via AJAX requests See #2509 --- diff --git a/wcfsetup/install/files/lib/system/form/builder/DialogFormDocument.class.php b/wcfsetup/install/files/lib/system/form/builder/DialogFormDocument.class.php index a9db94d53b..960db3b86d 100644 --- a/wcfsetup/install/files/lib/system/form/builder/DialogFormDocument.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/DialogFormDocument.class.php @@ -30,19 +30,6 @@ class DialogFormDocument extends FormDocument { return $this; } - /** - * @inheritDoc - */ - public function getAction() { - // do not throw exception if no action has been set as a dialog - // form does not require an action to be set - if ($this->action === null) { - $this->action = ''; - } - - return $this->action; - } - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php b/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php index c78f2243c7..5bdf588c4c 100644 --- a/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php @@ -31,6 +31,13 @@ class FormDocument implements IFormDocument { */ protected $action; + /** + * `true` if form is requested via an AJAX request or processes data via an AJAX request + * and `false` otherwise + * @var boolean + */ + protected $ajax; + /** * data handler for this document * @var IFormDataHandler @@ -90,6 +97,15 @@ class FormDocument implements IFormDocument { return $this; } + /** + * @inheritDoc + */ + public function ajax($ajax = true) { + $this->ajax = $ajax; + + return $this; + } + /** * @inheritDoc */ @@ -143,7 +159,7 @@ class FormDocument implements IFormDocument { * @inheritDoc */ public function getAction() { - if ($this->action === null) { + if ($this->action === null && !$this->isAjax()) { throw new \BadMethodCallException("Action has not been set."); } @@ -268,6 +284,13 @@ class FormDocument implements IFormDocument { return !empty($requestData); } + /** + * @inheritDoc + */ + public function isAjax() { + return $this->ajax; + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php b/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php index bb82d1e8c7..5f37e7ab57 100644 --- a/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php @@ -35,6 +35,15 @@ interface IFormDocument extends IFormParentNode { */ public function action($action); + /** + * Sets whether this form is requested via an AJAX request or processes data via an AJAX + * request and returns his document. + * + * @param boolean $ajax + * @return static this document + */ + public function ajax($ajax = true); + /** * Is called once after all nodes have been added to this document. * @@ -64,7 +73,7 @@ interface IFormDocument extends IFormParentNode { * * @return string form action * - * @throws \BadMethodCallException if no action has been set + * @throws \BadMethodCallException if no action has been set and `isAjax()` is `false` */ public function getAction(); @@ -149,6 +158,16 @@ interface IFormDocument extends IFormParentNode { */ public function hasRequestData($index = null); + /** + * Returns `true` if this form is requested via an AJAX request or processes data via an + * AJAX request and `false` otherwise. + * + * By default, this method returns `false`. + * + * @return boolean + */ + public function isAjax(); + /** * Loads the field values from the given object and returns this document. *