From: Joshua Rüsweg Date: Sun, 20 Jan 2019 18:59:54 +0000 (+0100) Subject: Unregister field, after destroy the form X-Git-Tag: 5.2.0_Alpha_1~296^2~29 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f2098a65260f34eebfc266ddce102e477400f4e1;p=GitHub%2FWoltLab%2FWCF.git Unregister field, after destroy the form See #2825 --- diff --git a/wcfsetup/install/files/lib/system/file/upload/UploadHandler.class.php b/wcfsetup/install/files/lib/system/file/upload/UploadHandler.class.php index 53bacb637a..36f19c026b 100644 --- a/wcfsetup/install/files/lib/system/file/upload/UploadHandler.class.php +++ b/wcfsetup/install/files/lib/system/file/upload/UploadHandler.class.php @@ -55,6 +55,26 @@ class UploadHandler extends SingletonFactory { } } + /** + * Unregisters an upload field by the given field id. + * + * @param string $fieldId + * + * @throws \InvalidArgumentException if the given fieldId is unknown + */ + public function unregisterUploadField($fieldId) { + if (!isset($this->fields[$fieldId])) { + throw new \InvalidArgumentException('UploadField with the id "'. $fieldId .'" is unknown.'); + } + + $storage = $this->getStorage(); + unset($storage[$this->fields[$fieldId]->getInternalId()]); + + WCF::getSession()->register(self::UPLOAD_HANDLER_SESSION_VAR, $storage); + + unset($this->fields[$fieldId]); + } + /** * Returns the uploaded files for a specific fieldId. * diff --git a/wcfsetup/install/files/lib/system/form/builder/field/UploadFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/UploadFormField.class.php index d145ca3f89..6b98265fee 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/UploadFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/UploadFormField.class.php @@ -40,6 +40,15 @@ class UploadFormField extends AbstractFormField { } } + /** + * Unregisters the current field in the upload handler. + */ + private function unregisterField() { + if (UploadHandler::getInstance()->isRegisteredFieldId($this->getId())) { + UploadHandler::getInstance()->unregisterUploadField($this->getId()); + } + } + /** * Builds the UploadField class. * @@ -147,6 +156,15 @@ class UploadFormField extends AbstractFormField { return false; } + /** + * @inheritDoc + */ + public function cleanup() { + $this->unregisterField(); + + return $this; + } + /** * @inheritDoc *