From 914a8fbad2b33e033363834fdac80fa14b7265e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Fri, 5 Apr 2019 20:26:13 +0200 Subject: [PATCH] Add parameter to add the request data to the UploadHandler See #2509 See #2825 --- .../lib/system/file/upload/UploadHandler.class.php | 11 ++++++++--- .../form/builder/field/UploadFormField.class.php | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) 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 1c32d969cc..80465ff79b 100644 --- a/wcfsetup/install/files/lib/system/file/upload/UploadHandler.class.php +++ b/wcfsetup/install/files/lib/system/file/upload/UploadHandler.class.php @@ -39,17 +39,22 @@ class UploadHandler extends SingletonFactory { * Registers a UploadField. * * @param UploadField $field + * @param mixed $requestData * * @throws \InvalidArgumentException if a field with the given fieldId is already registered */ - public function registerUploadField(UploadField $field) { + public function registerUploadField(UploadField $field, array $requestData = null) { if (isset($this->fields[$field->getFieldId()])) { throw new \InvalidArgumentException('UploadField with the id "'. $field->getFieldId() .'" is already registered.'); } + if ($requestData === null) { + $requestData = $_POST; + } + // read internal identifier - if (!empty($_POST) && isset($_POST[$field->getFieldId()]) && $this->isValidInternalId($_POST[$field->getFieldId()])) { - $field->setInternalId($_POST[$field->getFieldId()]); + if (!empty($requestData) && isset($requestData[$field->getFieldId()]) && $this->isValidInternalId($requestData[$field->getFieldId()])) { + $field->setInternalId($requestData[$field->getFieldId()]); $this->fields[$field->getFieldId()] = $field; } 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 c078d8aa4c..59f4ee2c0a 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 @@ -52,7 +52,7 @@ class UploadFormField extends AbstractFormField { */ private function registerField() { if (!UploadHandler::getInstance()->isRegisteredFieldId($this->getPrefixedId())) { - UploadHandler::getInstance()->registerUploadField($this->buildUploadField()); + UploadHandler::getInstance()->registerUploadField($this->buildUploadField(), $this->getDocument()->getRequestData()); } } -- 2.20.1