diff --git a/wcfsetup/install/files/lib/system/form/option/WysiwygFormOption.class.php b/wcfsetup/install/files/lib/system/form/option/WysiwygFormOption.class.php index 32a827e351..2efdab8779 100644 --- a/wcfsetup/install/files/lib/system/form/option/WysiwygFormOption.class.php +++ b/wcfsetup/install/files/lib/system/form/option/WysiwygFormOption.class.php @@ -18,6 +18,10 @@ */ class WysiwygFormOption extends AbstractFormOption { + private string $objectType; + + private int $objectID; + #[\Override] public function getId(): string { @@ -27,8 +31,12 @@ public function getId(): string #[\Override] public function getFormField(string $id, array $configuration = []): AbstractFormField { + if (!isset($this->objectType)) { + throw new \RuntimeException("The WYSIWYG context has not been set."); + } + return WysiwygFormField::create($id) - ->objectType('com.woltlab.wcf.genericFormOption'); + ->objectType($this->objectType); } #[\Override] @@ -40,13 +48,21 @@ public function getConfigurationFormFields(): array #[\Override] public function getFormatter(): IFormOptionFormatter { - return new WysiwygFormatter(); + if (!isset($this->objectType)) { + throw new \RuntimeException("The WYSIWYG context has not been set."); + } + + return new WysiwygFormatter($this->objectType, $this->objectID); } #[\Override] public function getPlainTextFormatter(): IFormOptionFormatter { - return new WysiwygPlainTextFormatter(); + if (!isset($this->objectType)) { + throw new \RuntimeException("The WYSIWYG context has not been set."); + } + + return new WysiwygPlainTextFormatter($this->objectType, $this->objectID); } #[\Override] @@ -60,4 +76,13 @@ public function isFilterable(): bool { return false; } + + /** + * Sets the context for the HTML processors. + */ + public function setContext(string $objectType, int $objectID): void + { + $this->objectType = $objectType; + $this->objectID = $objectID; + } } diff --git a/wcfsetup/install/files/lib/system/form/option/formatter/WysiwygFormatter.class.php b/wcfsetup/install/files/lib/system/form/option/formatter/WysiwygFormatter.class.php index 0803b2db32..a0e9040284 100644 --- a/wcfsetup/install/files/lib/system/form/option/formatter/WysiwygFormatter.class.php +++ b/wcfsetup/install/files/lib/system/form/option/formatter/WysiwygFormatter.class.php @@ -14,11 +14,16 @@ */ final class WysiwygFormatter implements IFormOptionFormatter { + public function __construct( + private readonly string $objectType, + private readonly int $objectID, + ) {} + #[\Override] public function format(string $value, int $languageID, array $configuration): string { $processor = new HtmlOutputProcessor(); - $processor->process($value, 'com.woltlab.wcf.genericFormOption', 0, true, $languageID); + $processor->process($value, $this->objectType, $this->objectID, true, $languageID); return $processor->getHtml(); } diff --git a/wcfsetup/install/files/lib/system/form/option/formatter/WysiwygPlainTextFormatter.class.php b/wcfsetup/install/files/lib/system/form/option/formatter/WysiwygPlainTextFormatter.class.php index 1194564432..c0ecf3e2e2 100644 --- a/wcfsetup/install/files/lib/system/form/option/formatter/WysiwygPlainTextFormatter.class.php +++ b/wcfsetup/install/files/lib/system/form/option/formatter/WysiwygPlainTextFormatter.class.php @@ -14,12 +14,17 @@ */ final class WysiwygPlainTextFormatter implements IFormOptionFormatter { + public function __construct( + private readonly string $objectType, + private readonly int $objectID, + ) {} + #[\Override] public function format(string $value, int $languageID, array $configuration): string { $processor = new HtmlOutputProcessor(); $processor->setOutputType('text/plain'); - $processor->process($value, 'com.woltlab.wcf.genericFormOption', 0, true, $languageID); + $processor->process($value, $this->objectType, $this->objectID, true, $languageID); return $processor->getHtml(); }