Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
*/
class WysiwygFormOption extends AbstractFormOption
{
private string $objectType;

private int $objectID;

#[\Override]
public function getId(): string
{
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down