From a2322d156a0e556318969df1d4d388dded4790dc Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 9 May 2023 16:19:41 +0200 Subject: [PATCH] Fix the retrieval of the contents of a CKEditor form field Fixes #5480 --- .../Core/Form/Builder/Field/Ckeditor.ts | 29 +++++++++++++++++++ .../Core/Form/Builder/Field/Ckeditor.js | 27 +++++++++++++++++ .../field/wysiwyg/WysiwygFormField.class.php | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 ts/WoltLabSuite/Core/Form/Builder/Field/Ckeditor.ts create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Ckeditor.js diff --git a/ts/WoltLabSuite/Core/Form/Builder/Field/Ckeditor.ts b/ts/WoltLabSuite/Core/Form/Builder/Field/Ckeditor.ts new file mode 100644 index 0000000000..e7ff2eb0a9 --- /dev/null +++ b/ts/WoltLabSuite/Core/Form/Builder/Field/Ckeditor.ts @@ -0,0 +1,29 @@ +/** + * Data handler for CKEditor. + * + * @author Alexander Ebert + * @copyright 2001-2023 WoltLab GmbH + * @license GNU Lesser General Public License + * @since 6.0 + */ + +import Field from "./Field"; +import { FormBuilderData } from "../Data"; +import { dispatchToCkeditor } from "WoltLabSuite/Core/Component/Ckeditor/Event"; +import { getCkeditorById } from "WoltLabSuite/Core/Component/Ckeditor"; + +export class Ckeditor extends Field { + protected _getData(): FormBuilderData { + const ckeditor = getCkeditorById(this._fieldId)!; + + return { + [this._fieldId]: ckeditor.getHtml(), + }; + } + + destroy(): void { + dispatchToCkeditor(this._field!).destroy(); + } +} + +export default Ckeditor; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Ckeditor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Ckeditor.js new file mode 100644 index 0000000000..113113fdd8 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Ckeditor.js @@ -0,0 +1,27 @@ +/** + * Data handler for CKEditor. + * + * @author Alexander Ebert + * @copyright 2001-2023 WoltLab GmbH + * @license GNU Lesser General Public License + * @since 6.0 + */ +define(["require", "exports", "tslib", "./Field", "WoltLabSuite/Core/Component/Ckeditor/Event", "WoltLabSuite/Core/Component/Ckeditor"], function (require, exports, tslib_1, Field_1, Event_1, Ckeditor_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.Ckeditor = void 0; + Field_1 = tslib_1.__importDefault(Field_1); + class Ckeditor extends Field_1.default { + _getData() { + const ckeditor = (0, Ckeditor_1.getCkeditorById)(this._fieldId); + return { + [this._fieldId]: ckeditor.getHtml(), + }; + } + destroy() { + (0, Event_1.dispatchToCkeditor)(this._field).destroy(); + } + } + exports.Ckeditor = Ckeditor; + exports.default = Ckeditor; +}); diff --git a/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php index 1ce91a39c5..15d88f9253 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php @@ -89,7 +89,7 @@ final class WysiwygFormField extends AbstractFormField implements /** * @inheritDoc */ - protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Value'; + protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Ckeditor'; /** * @inheritDoc -- 2.20.1