From 25e9a54f43eaf14cc1b207502622186bf0d8a978 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 5 Jan 2019 11:13:28 +0100 Subject: [PATCH] Add IFormNode::cleanup() See #2509 --- .../lib/form/AbstractFormBuilderForm.class.php | 2 ++ .../system/form/builder/FormDocument.class.php | 8 ++++++++ .../lib/system/form/builder/IFormNode.class.php | 10 ++++++++++ .../lib/system/form/builder/TFormNode.class.php | 12 ++++++++++++ .../form/builder/TFormParentNode.class.php | 16 ++++++++++++++++ .../builder/container/FormContainer.class.php | 1 + 6 files changed, 49 insertions(+) diff --git a/wcfsetup/install/files/lib/form/AbstractFormBuilderForm.class.php b/wcfsetup/install/files/lib/form/AbstractFormBuilderForm.class.php index 5ae9d08973..49f3bb5cf4 100644 --- a/wcfsetup/install/files/lib/form/AbstractFormBuilderForm.class.php +++ b/wcfsetup/install/files/lib/form/AbstractFormBuilderForm.class.php @@ -156,6 +156,8 @@ abstract class AbstractFormBuilderForm extends AbstractForm { // re-build form after having created a new object if ($this->formAction === 'create') { + $this->form->cleanup(); + $this->buildForm(); } 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 005233e526..f913405654 100644 --- a/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php @@ -20,6 +20,7 @@ use wcf\system\WCF; class FormDocument implements IFormDocument { use TFormNode; use TFormParentNode { + TFormParentNode::cleanup insteadof TFormNode; readValues as protected defaultReadValues; } @@ -72,6 +73,13 @@ class FormDocument implements IFormDocument { */ protected $isBuilt = false; + /** + * Cleans up the form document before the form document object is destroyed. + */ + public function __destruct() { + $this->cleanup(); + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/form/builder/IFormNode.class.php b/wcfsetup/install/files/lib/system/form/builder/IFormNode.class.php index 909228c1fe..cc1aec319d 100644 --- a/wcfsetup/install/files/lib/system/form/builder/IFormNode.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/IFormNode.class.php @@ -70,6 +70,16 @@ interface IFormNode { */ public function available($available = true); + /** + * Cleans up after the whole form is not used anymore. + * This method has to support being called multiple times. + * + * This form should not clean up input fields. + * + * @return static this node + */ + public function cleanup(); + /** * Returns `true` if all of the node's dependencies are met and returns `false` otherwise. * diff --git a/wcfsetup/install/files/lib/system/form/builder/TFormNode.class.php b/wcfsetup/install/files/lib/system/form/builder/TFormNode.class.php index d557181c3c..2f5c57b43f 100644 --- a/wcfsetup/install/files/lib/system/form/builder/TFormNode.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/TFormNode.class.php @@ -177,6 +177,18 @@ trait TFormNode { return true; } + /** + * Cleans up after the whole form is not used anymore. + * This method has to support being called multiple times. + * + * This form should not clean up input fields. + * + * @return static this node + */ + public function cleanup() { + return $this; + } + /** * Returns the value of the additional attribute of this node with the given name. * diff --git a/wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php b/wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php index c95da5802b..d33f036346 100644 --- a/wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php @@ -92,6 +92,22 @@ trait TFormParentNode { return $this->__children; } + /** + * Cleans up after the whole form is not used anymore. + * This method has to support being called multiple times. + * + * This form should not clean up input fields. + * + * @return static this node + */ + public function cleanup() { + foreach ($this as $child) { + $child->cleanup(); + } + + return $this; + } + /** * Returns the number of direct children of this node. * diff --git a/wcfsetup/install/files/lib/system/form/builder/container/FormContainer.class.php b/wcfsetup/install/files/lib/system/form/builder/container/FormContainer.class.php index 5327d21b5e..0ede5819f5 100644 --- a/wcfsetup/install/files/lib/system/form/builder/container/FormContainer.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/container/FormContainer.class.php @@ -20,6 +20,7 @@ class FormContainer implements IFormContainer { use TFormChildNode; use TFormElement; use TFormParentNode { + TFormParentNode::cleanup insteadof TFormElement; validateChild as protected defaultValidateChild; } -- 2.20.1