Skip to content

Commit

Permalink
Merge pull request #459 from WoltLab/migration/quote-load-embedded-ob…
Browse files Browse the repository at this point in the history
…jects

Document how to load embedded objects for quote
  • Loading branch information
Cyperghost authored Aug 23, 2024
2 parents c8ab579 + f608dbd commit bfd5e39
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions docs/migration/wsc60/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
```

0 comments on commit bfd5e39

Please sign in to comment.