From 7dfedf8d08ba4ea5117f99718b56d0de3f01f87e Mon Sep 17 00:00:00 2001 From: ilou <8680610+ilouHD@users.noreply.github.com> Date: Mon, 17 Aug 2020 18:44:31 +0200 Subject: [PATCH] Allow disabling preview button in WYSIWYG form container --- .../wysiwyg/WysiwygFormContainer.class.php | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php b/wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php index c90f89314d..08267cbf73 100644 --- a/wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php @@ -46,6 +46,13 @@ class WysiwygFormContainer extends FormContainer { */ protected $attachmentData; + /** + * `true` if the preview button should be shown and `false` otherwise + * @var bool + * @since 5.3 + */ + protected $enablePreviewButton = true; + /** * name of the relevant message object type * @var string @@ -206,6 +213,21 @@ class WysiwygFormContainer extends FormContainer { return $this; } + /** + * Sets whether the preview button should be shown or not and returns this form container. + * + * By default, the preview button is shown. + * + * @param bool $enablePreviewButton + * @return WysiwygFormContainer this form container + * @since 5.3 + */ + public function enablePreviewButton($enablePreviewButton = true) { + $this->enablePreviewButton = $enablePreviewButton; + + return $this; + } + /** * Returns the form field handling attachments. * @@ -316,6 +338,18 @@ class WysiwygFormContainer extends FormContainer { return $this->required; } + /** + * Returns `true` if the preview button will be shown and returns `false` otherwise. + * + * By default, the preview button is shown. + * + * @return bool + * @since 5.3 + */ + public function isPreviewButtonEnabled() { + return $this->enablePreviewButton; + } + /** * @since 5.3 * @inheritDoc @@ -448,12 +482,14 @@ class WysiwygFormContainer extends FormContainer { $this->setAttachmentHandler(); } - $this->getDocument()->addButton( - WysiwygPreviewFormButton::create($this->getWysiwygId() . 'PreviewButton') - ->objectType($this->messageObjectType) - ->wysiwygId($this->getWysiwygId()) - ->objectId($this->getObjectId()) - ); + if ($this->enablePreviewButton) { + $this->getDocument()->addButton( + WysiwygPreviewFormButton::create($this->getWysiwygId() . 'PreviewButton') + ->objectType($this->messageObjectType) + ->wysiwygId($this->getWysiwygId()) + ->objectId($this->getObjectId()) + ); + } EventHandler::getInstance()->fireAction($this, 'populate'); } -- 2.20.1