From: Matthias Schmidt Date: Sun, 3 Mar 2019 14:49:41 +0000 (+0100) Subject: Refresh wysiwyg form field attachment handler when loading object id X-Git-Tag: 5.2.0_Alpha_1~249 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=19c9e50d8745a44f39ce5be6a0c367e94c9fd086;p=GitHub%2FWoltLab%2FWCF.git Refresh wysiwyg form field attachment handler when loading object id See 712125889cef56d5f23881c8f2fbfc4bacb4d8e5 See #2852 --- diff --git a/wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php b/wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php index 70eb0ea400..bc36751a65 100644 --- a/wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php @@ -156,6 +156,18 @@ class WysiwygFormContainer extends FormContainer { public function loadValuesFromObject(IStorableObject $object) { $this->objectId = $object->getObjectID(); + if ($this->attachmentData !== null) { + // updated attachment handler with object id + $this->attachmentField->attachmentHandler( + new AttachmentHandler( + $this->attachmentData['objectType'], + $this->getObjectId(), + '.', + $this->attachmentData['parentObjectID'] + ) + ); + } + return parent::loadValuesFromObject($object); } diff --git a/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygAttachmentFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygAttachmentFormField.class.php index 8b7eaa0e5f..4666c08808 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygAttachmentFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygAttachmentFormField.class.php @@ -53,18 +53,24 @@ class WysiwygAttachmentFormField extends AbstractFormField { * @return WysiwygAttachmentFormField */ public function attachmentHandler(AttachmentHandler $attachmentHandler = null) { - if ($this->attachmentHandler === null && $attachmentHandler !== null) { - $tmpHash = StringUtil::getRandomID(); - if ($this->getDocument()->isAjax()) { - $sessionTmpHash = WCF::getSession()->getVar('__wcfAttachmentTmpHash'); - if ($sessionTmpHash !== null) { - $tmpHash = $sessionTmpHash; - - WCF::getSession()->unregister('__wcfAttachmentTmpHash'); + if ($attachmentHandler !== null) { + if ($this->attachmentHandler === null) { + $tmpHash = StringUtil::getRandomID(); + if ($this->getDocument()->isAjax()) { + $sessionTmpHash = WCF::getSession()->getVar('__wcfAttachmentTmpHash'); + if ($sessionTmpHash !== null) { + $tmpHash = $sessionTmpHash; + + WCF::getSession()->unregister('__wcfAttachmentTmpHash'); + } } + + $attachmentHandler->setTmpHashes([$tmpHash]); + } + else { + // preserve temporary hashes + $attachmentHandler->setTmpHashes($this->attachmentHandler->getTmpHashes()); } - - $attachmentHandler->setTmpHashes([$tmpHash]); } $this->attachmentHandler = $attachmentHandler;