Add a migration description of how embedded objects should be loaded to quotes before...
authorOlaf Braun <info@braun-development.de>
Fri, 23 Aug 2024 13:53:29 +0000 (15:53 +0200)
committerOlaf Braun <info@braun-development.de>
Fri, 23 Aug 2024 13:53:29 +0000 (15:53 +0200)
docs/migration/wsc60/php.md

index 2fc6731e0ec68a5d6fa4f07d958a9f3b5fccb3cd..f7de6409711aff402d832b50cc581b967c9977de 100644 (file)
@@ -146,3 +146,55 @@ class FooBarCategoryEditForm extends FooBarCategoryAddForm {
 
 See [WoltLab/WCF#5657](https://github.com/WoltLab/WCF/pull/5657
 ) for more details. 
+
+## Loading embedded objects for quotes
+
+When saving a quote, it is necessary to load embedded objects before adding the quote to the `MessageQuoteManager`.
+This is to ensure that the embedded objects are displayed correctly in the quote preview.
+
+```PHP
+public class FooBarAction extends AbstractDatabaseObjectAction implements IMessageQuoteAction
+{   
+    private function loadEmbeddedObjects(): void
+    {
+        if ($this->object->hasEmbeddedObjects) {
+            ObjectTypeCache::getInstance()
+                ->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'foo.bar.attachment')
+                ->getProcessor()
+                ->cacheObjects([$this->object->objectID]);
+            MessageEmbeddedObjectManager::getInstance()->loadObjects(
+                'foo.bar.message',
+                [$this->object->objectID]
+            );
+        }
+    }
+
+    public function saveFullQuote()
+    {
+        $this->loadEmbeddedObjects();
+
+        $quoteID = MessageQuoteManager::getInstance()->addQuote(
+            'foo.bar.message',
+            $this->object->parentObjectID,
+            $this->object->objectID,
+            $this->object->getExcerpt(),
+            $this->object->getMessage()
+        );
+        …
+    }
+
+    public function saveQuote()
+    {
+        $this->loadEmbeddedObjects();
+
+        $quoteID = MessageQuoteManager::getInstance()->addQuote(
+            'foo.bar.message',
+            $this->object->parentObjectID,
+            $this->object->objectID,
+            $this->parameters['message'],
+            false
+        );
+        …
+    }
+}
+```