Refresh wysiwyg form field attachment handler when loading object id
authorMatthias Schmidt <gravatronics@live.com>
Sun, 3 Mar 2019 14:49:41 +0000 (15:49 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 3 Mar 2019 14:49:41 +0000 (15:49 +0100)
See 712125889cef56d5f23881c8f2fbfc4bacb4d8e5
See #2852

wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php
wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygAttachmentFormField.class.php

index 70eb0ea40092295cc00a98ad82bdad98cca857d9..bc36751a65abbc44c397847088fea145485a2e8b 100644 (file)
@@ -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);
        }
 
index 8b7eaa0e5f8f432242388815f8f675c8e2a2ec97..4666c088080836db459185a3065f9e318047f4c4 100644 (file)
@@ -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;