Skip to content

Commit 9c24474

Browse files
committed
Add support for the context of a WysiwygFormOption
See https://www.woltlab.com/community/thread/315782/
1 parent 58fc69a commit 9c24474

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

wcfsetup/install/files/lib/system/form/option/WysiwygFormOption.class.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
*/
1919
class WysiwygFormOption extends AbstractFormOption
2020
{
21+
private string $objectType;
22+
23+
private int $objectID;
24+
2125
#[\Override]
2226
public function getId(): string
2327
{
@@ -27,8 +31,12 @@ public function getId(): string
2731
#[\Override]
2832
public function getFormField(string $id, array $configuration = []): AbstractFormField
2933
{
34+
if (!isset($this->objectType)) {
35+
throw new \RuntimeException("The WYSIWYG context has not been set.");
36+
}
37+
3038
return WysiwygFormField::create($id)
31-
->objectType('com.woltlab.wcf.genericFormOption');
39+
->objectType($this->objectType);
3240
}
3341

3442
#[\Override]
@@ -40,13 +48,21 @@ public function getConfigurationFormFields(): array
4048
#[\Override]
4149
public function getFormatter(): IFormOptionFormatter
4250
{
43-
return new WysiwygFormatter();
51+
if (!isset($this->objectType)) {
52+
throw new \RuntimeException("The WYSIWYG context has not been set.");
53+
}
54+
55+
return new WysiwygFormatter($this->objectType, $this->objectID);
4456
}
4557

4658
#[\Override]
4759
public function getPlainTextFormatter(): IFormOptionFormatter
4860
{
49-
return new WysiwygPlainTextFormatter();
61+
if (!isset($this->objectType)) {
62+
throw new \RuntimeException("The WYSIWYG context has not been set.");
63+
}
64+
65+
return new WysiwygPlainTextFormatter($this->objectType, $this->objectID);
5066
}
5167

5268
#[\Override]
@@ -60,4 +76,13 @@ public function isFilterable(): bool
6076
{
6177
return false;
6278
}
79+
80+
/**
81+
* Sets the context for the HTML processors.
82+
*/
83+
public function setContext(string $objectType, int $objectID): void
84+
{
85+
$this->objectType = $objectType;
86+
$this->objectID = $objectID;
87+
}
6388
}

wcfsetup/install/files/lib/system/form/option/formatter/WysiwygFormatter.class.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
*/
1515
final class WysiwygFormatter implements IFormOptionFormatter
1616
{
17+
public function __construct(
18+
private readonly string $objectType,
19+
private readonly int $objectID,
20+
) {}
21+
1722
#[\Override]
1823
public function format(string $value, int $languageID, array $configuration): string
1924
{
2025
$processor = new HtmlOutputProcessor();
21-
$processor->process($value, 'com.woltlab.wcf.genericFormOption', 0, true, $languageID);
26+
$processor->process($value, $this->objectType, $this->objectID, true, $languageID);
2227

2328
return $processor->getHtml();
2429
}

wcfsetup/install/files/lib/system/form/option/formatter/WysiwygPlainTextFormatter.class.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
*/
1515
final class WysiwygPlainTextFormatter implements IFormOptionFormatter
1616
{
17+
public function __construct(
18+
private readonly string $objectType,
19+
private readonly int $objectID,
20+
) {}
21+
1722
#[\Override]
1823
public function format(string $value, int $languageID, array $configuration): string
1924
{
2025
$processor = new HtmlOutputProcessor();
2126
$processor->setOutputType('text/plain');
22-
$processor->process($value, 'com.woltlab.wcf.genericFormOption', 0, true, $languageID);
27+
$processor->process($value, $this->objectType, $this->objectID, true, $languageID);
2328

2429
return $processor->getHtml();
2530
}

0 commit comments

Comments
 (0)