Add data handler for upload form fields
authorJoshua Rüsweg <josh@bastelstu.be>
Sun, 3 Feb 2019 18:22:11 +0000 (19:22 +0100)
committerJoshua Rüsweg <josh@bastelstu.be>
Sun, 3 Feb 2019 18:22:22 +0000 (19:22 +0100)
See #2825

wcfsetup/install/files/lib/system/form/builder/field/UploadFormField.class.php

index a0dd65bf74b5af60b2e7e3c61c26f0664a15f2d8..3c0dff9dae1bab7ea02bbc0f98b23a4123d1f83a 100644 (file)
@@ -3,7 +3,9 @@ namespace wcf\system\form\builder\field;
 use wcf\system\file\upload\UploadField;
 use wcf\system\file\upload\UploadFile;
 use wcf\system\file\upload\UploadHandler;
+use wcf\system\form\builder\field\data\processor\CustomFormFieldDataProcessor;
 use wcf\system\form\builder\field\validation\FormFieldValidationError;
+use wcf\system\form\builder\IFormDocument;
 
 /**
  * Implementation of a form field for to uploads.
@@ -194,6 +196,22 @@ class UploadFormField extends AbstractFormField {
                return $this;
        }
        
+       /**
+        * @inheritDoc
+        */
+       public function populate() {
+               parent::populate();
+               
+               $this->getDocument()->getDataHandler()->add(new CustomFormFieldDataProcessor('upload', function(IFormDocument $document, array $parameters) {
+                       $parameters[$this->getId()] = $this->getValue();
+                       $parameters[$this->getId() . '_removedFiles'] = $this->getRemovedFiles(true);
+                       
+                       return $parameters;
+               }));
+               
+               return $this;
+       }
+       
        /**
         * @inheritDoc
         *