Skip to content

Commit 58f9721

Browse files
committed
Add "wysiwyg" form option type
1 parent 047b331 commit 58f9721

File tree

7 files changed

+122
-0
lines changed

7 files changed

+122
-0
lines changed

com.woltlab.wcf/objectType.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@
157157
<definitionname>com.woltlab.wcf.message</definitionname>
158158
<disallowedBBCodesPermission>user.signature.disallowedBBCodes</disallowedBBCodesPermission>
159159
</type>
160+
<type>
161+
<name>com.woltlab.wcf.genericFormOption</name>
162+
<definitionname>com.woltlab.wcf.message</definitionname>
163+
</type>
160164
<type>
161165
<name>com.woltlab.wcf.user.signature</name>
162166
<definitionname>com.woltlab.wcf.attachment.objectType</definitionname>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private function getDefaultFormOptions(): array
5252
new TextFormOption(),
5353
new TextareaFormOption(),
5454
new UrlFormOption(),
55+
new WysiwygFormOption(),
5556
] as $defaultOption
5657
) {
5758
$options[$defaultOption->getId()] = $defaultOption;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace wcf\system\form\option;
4+
5+
use wcf\data\DatabaseObjectList;
6+
use wcf\system\form\builder\field\TextFormField;
7+
use wcf\system\form\builder\field\wysiwyg\WysiwygFormField;
8+
use wcf\system\form\option\formatter\WysiwygFormatter;
9+
use wcf\system\form\option\formatter\WysiwygPlainTextFormatter;
10+
use wcf\system\WCF;
11+
12+
/**
13+
* Implementation of a form option using the WYSIWYG editor.
14+
*
15+
* @author Marcel Werk
16+
* @copyright 2001-2025 WoltLab GmbH
17+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18+
* @since 6.2
19+
*/
20+
class WysiwygFormOption extends AbstractFormOption
21+
{
22+
#[\Override]
23+
public function getId(): string
24+
{
25+
return 'wysiwyg';
26+
}
27+
28+
#[\Override]
29+
public function getFilterFormField(string $id, array $configurationData = []): TextFormField
30+
{
31+
return TextFormField::create($id);
32+
}
33+
34+
#[\Override]
35+
public function getFormField(string $id, array $configurationData = []): WysiwygFormField
36+
{
37+
return WysiwygFormField::create($id)
38+
->objectType('com.woltlab.wcf.genericFormOption');
39+
}
40+
41+
#[\Override]
42+
public function getConfigurationFormFields(): array
43+
{
44+
return ['required'];
45+
}
46+
47+
#[\Override]
48+
public function applyFilter(DatabaseObjectList $list, string $columnName, mixed $value): void
49+
{
50+
$list->getConditionBuilder()->add("{$columnName} LIKE ?", ['%' . WCF::getDB()->escapeLikeValue($value) . '%']);
51+
}
52+
53+
#[\Override]
54+
public function getFormatter(): WysiwygFormatter
55+
{
56+
return new WysiwygFormatter();
57+
}
58+
59+
#[\Override]
60+
public function getPlainTextFormatter(): WysiwygPlainTextFormatter
61+
{
62+
return new WysiwygPlainTextFormatter();
63+
}
64+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace wcf\system\form\option\formatter;
4+
5+
use wcf\system\html\output\HtmlOutputProcessor;
6+
7+
/**
8+
* Formatter for wysiwyg form options.
9+
*
10+
* @author Marcel Werk
11+
* @copyright 2001-2025 WoltLab GmbH
12+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
* @since 6.2
14+
*/
15+
final class WysiwygFormatter implements IFormOptionFormatter
16+
{
17+
#[\Override]
18+
public function format(string $value, int $languageID, array $configurationData): string
19+
{
20+
$processor = new HtmlOutputProcessor();
21+
$processor->process($value, 'com.woltlab.wcf.genericFormOption', 0, true, $languageID);
22+
23+
return $processor->getHtml();
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace wcf\system\form\option\formatter;
4+
5+
use wcf\system\html\output\HtmlOutputProcessor;
6+
7+
/**
8+
* Plain text version of the formatter for wysiwyg form options.
9+
*
10+
* @author Marcel Werk
11+
* @copyright 2001-2025 WoltLab GmbH
12+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
* @since 6.2
14+
*/
15+
final class WysiwygPlainTextFormatter implements IFormOptionFormatter
16+
{
17+
#[\Override]
18+
public function format(string $value, int $languageID, array $configurationData): string
19+
{
20+
$processor = new HtmlOutputProcessor();
21+
$processor->setOutputType('text/plain');
22+
$processor->process($value, 'com.woltlab.wcf.genericFormOption', 0, true, $languageID);
23+
24+
return $processor->getHtml();
25+
}
26+
}

wcfsetup/install/lang/de.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4129,6 +4129,7 @@ Dateianhänge:
41294129
<item name="wcf.form.option.textarea"><![CDATA[Mehrzeiliger Text]]></item>
41304130
<item name="wcf.form.option.sourceCode"><![CDATA[Quellcode]]></item>
41314131
<item name="wcf.form.option.url"><![CDATA[Link]]></item>
4132+
<item name="wcf.form.option.wysiwyg"><![CDATA[Wysiwyg]]></item>
41324133
<item name="wcf.form.option.shared.currency"><![CDATA[Währung]]></item>
41334134
<item name="wcf.form.option.shared.defaultValue"><![CDATA[Standardwert]]></item>
41344135
<item name="wcf.form.option.shared.maxLength"><![CDATA[Maximale Textlänge]]></item>

wcfsetup/install/lang/en.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4075,6 +4075,7 @@ Attachments:
40754075
<item name="wcf.form.option.textarea"><![CDATA[Multiline text]]></item>
40764076
<item name="wcf.form.option.sourceCode"><![CDATA[Source code]]></item>
40774077
<item name="wcf.form.option.url"><![CDATA[Link]]></item>
4078+
<item name="wcf.form.option.wysiwyg"><![CDATA[Wysiwyg]]></item>
40784079
<item name="wcf.form.option.shared.currency"><![CDATA[Currency]]></item>
40794080
<item name="wcf.form.option.shared.defaultValue"><![CDATA[Default Value]]></item>
40804081
<item name="wcf.form.option.shared.maxLength"><![CDATA[Maximum Text Length]]></item>

0 commit comments

Comments
 (0)