Add IFormNode::cleanup()
authorMatthias Schmidt <gravatronics@live.com>
Sat, 5 Jan 2019 10:13:28 +0000 (11:13 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 5 Jan 2019 10:13:28 +0000 (11:13 +0100)
See #2509

wcfsetup/install/files/lib/form/AbstractFormBuilderForm.class.php
wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php
wcfsetup/install/files/lib/system/form/builder/IFormNode.class.php
wcfsetup/install/files/lib/system/form/builder/TFormNode.class.php
wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php
wcfsetup/install/files/lib/system/form/builder/container/FormContainer.class.php

index 5ae9d08973605a7abeb6dd53c83bfd588d523e00..49f3bb5cf41ebe14f023a7f3b54114c783074b88 100644 (file)
@@ -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();
                }
                
index 005233e526ece63b6a0c5ceb73fd6eea21fec6d1..f9134056543a8be5c2150708355a880a50c6d6d6 100644 (file)
@@ -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
         */
index 909228c1fea5099f381011541c3f57f64dc6f03b..cc1aec319d08e23b16f9ea587b3108c36425e22d 100644 (file)
@@ -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.
         *
index d557181c3c6a3a5e2e94d950fc691303c8c2ace6..2f5c57b43fc22d36603268f6098c790df9839153 100644 (file)
@@ -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.
         * 
index c95da5802b2a9e79eca62910da72ace166431b7a..d33f036346800ea9269e93e80d57929fde2ebefe 100644 (file)
@@ -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.
         * 
index 5327d21b5ecf0268a1e9a52a4fefef92505d08ee..0ede5819f596a1e7de146610a939850dc6704ba7 100644 (file)
@@ -20,6 +20,7 @@ class FormContainer implements IFormContainer {
        use TFormChildNode;
        use TFormElement;
        use TFormParentNode {
+               TFormParentNode::cleanup insteadof TFormElement;
                validateChild as protected defaultValidateChild;
        }