Allow disabling preview button in WYSIWYG form container
authorilou <8680610+ilouHD@users.noreply.github.com>
Mon, 17 Aug 2020 16:44:31 +0000 (18:44 +0200)
committerGitHub <noreply@github.com>
Mon, 17 Aug 2020 16:44:31 +0000 (18:44 +0200)
wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php

index c90f89314d2b7b72607e23b4706a667f6c348b97..08267cbf731c32ac2c9e919008d010ab01063106 100644 (file)
@@ -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');
        }