From e4bb2699ab256cbd070908f26e63095a1d1058bf Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 30 Jun 2019 15:11:11 +0200 Subject: [PATCH] Expose additional settings of WysiwygFormField in WysiwygFormContainer See #2852 --- .../wysiwyg/WysiwygFormContainer.class.php | 39 ++++++++++++++++++- .../builder/field/AbstractFormField.class.php | 2 +- 2 files changed, 39 insertions(+), 2 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 c5afc06f24..5a5a57e5c1 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 @@ -7,6 +7,10 @@ use wcf\system\event\EventHandler; use wcf\system\form\builder\button\wysiwyg\WysiwygPreviewFormButton; use wcf\system\form\builder\container\FormContainer; use wcf\system\form\builder\container\TabFormContainer; +use wcf\system\form\builder\field\IMaximumLengthFormField; +use wcf\system\form\builder\field\IMinimumLengthFormField; +use wcf\system\form\builder\field\TMaximumLengthFormField; +use wcf\system\form\builder\field\TMinimumLengthFormField; use wcf\system\form\builder\field\wysiwyg\WysiwygAttachmentFormField; use wcf\system\form\builder\field\wysiwyg\WysiwygFormField; use wcf\system\form\builder\IFormNode; @@ -26,7 +30,9 @@ use wcf\system\form\builder\TWysiwygFormNode; * @package WoltLabSuite\Core\System\Form\Builder\Container\Wysiwyg * @since 5.2 */ -class WysiwygFormContainer extends FormContainer { +class WysiwygFormContainer extends FormContainer implements IMaximumLengthFormField, IMinimumLengthFormField { + use TMaximumLengthFormField; + use TMinimumLengthFormField; use TWysiwygFormNode; /** @@ -78,6 +84,12 @@ class WysiwygFormContainer extends FormContainer { */ protected $quoteData; + /** + * `true` if the wysiwyg field has to be filled out and `false` otherwise + * @var bool + */ + protected $required = false; + /** * settings form container * @var FormContainer @@ -295,6 +307,16 @@ class WysiwygFormContainer extends FormContainer { return parent::id($id); } + /** + * Returns `true` if the wsyiwyg field has to be filled out and returns `false` otherwise. + * By default, the wsyiwyg field does not have to be filled out. + * + * @return bool + */ + public function isRequired() { + return $this->required; + } + /** * Sets the message object type used by the wysiwyg form field. * @@ -370,6 +392,9 @@ class WysiwygFormContainer extends FormContainer { $this->wysiwygField = WysiwygFormField::create($this->wysiwygId) ->objectType($this->messageObjectType) + ->minimumLength($this->getMinimumLength()) + ->maximumLength($this->getMaximumLength()) + ->required($this->isRequired()) ->supportAttachments($this->attachmentData !== null) ->supportMentions($this->supportMentions) ->supportQuotes($this->supportQuotes); @@ -487,6 +512,18 @@ class WysiwygFormContainer extends FormContainer { return $this; } + /** + * Sets whether it is required to fill out the wysiwyg field and returns this container. + * + * @param bool $required determines if field has to be filled out + * @return static this container + */ + public function required($required = true) { + $this->required = $required; + + return $this; + } + /** * Sets if mentions are supported by the editor field and returns this form container. * diff --git a/wcfsetup/install/files/lib/system/form/builder/field/AbstractFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/AbstractFormField.class.php index 738cb2960b..a1b10e21eb 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/AbstractFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/AbstractFormField.class.php @@ -34,7 +34,7 @@ abstract class AbstractFormField implements IFormField { protected $objectProperty; /** - * `true` if this field has to be filled out and returns `false` otherwise + * `true` if this field has to be filled out and `false` otherwise * @var bool */ protected $required = false; -- 2.20.1