From aa6f853584182980c1c7d12891b689317e458b8b Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 13 Jan 2019 10:54:16 +0100 Subject: [PATCH] Move form field immutability to separate interface And add immutability support for some additional fields. See #2509 --- com.woltlab.wcf/templates/__iconFormField.tpl | 44 ++++++++++--------- .../__multipleSelectionFormField.tpl | 10 ++++- .../templates/__singleSelectionFormField.tpl | 15 ++++++- .../files/acp/templates/__iconFormField.tpl | 44 ++++++++++--------- .../__multipleSelectionFormField.tpl | 10 ++++- .../templates/__singleSelectionFormField.tpl | 15 ++++++- .../builder/field/AbstractFormField.class.php | 22 ---------- .../field/AbstractNumericFormField.class.php | 3 +- .../builder/field/BooleanFormField.class.php | 4 +- .../builder/field/DateFormField.class.php | 4 +- .../form/builder/field/IFormField.class.php | 16 ------- .../field/IImmutableFormField.class.php | 29 ++++++++++++ .../builder/field/IconFormField.class.php | 4 +- .../builder/field/ItemListFormField.class.php | 4 +- .../MultipleSelectionFormField.class.php | 3 +- .../field/RadioButtonFormField.class.php | 3 +- .../field/SingleSelectionFormField.class.php | 3 +- .../field/TImmutableFormField.class.php | 41 +++++++++++++++++ .../builder/field/TextFormField.class.php | 3 +- .../field/user/UserFormField.class.php | 5 ++- .../field/user/UsernameFormField.class.php | 5 ++- 21 files changed, 190 insertions(+), 97 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/form/builder/field/IImmutableFormField.class.php create mode 100644 wcfsetup/install/files/lib/system/form/builder/field/TImmutableFormField.class.php diff --git a/com.woltlab.wcf/templates/__iconFormField.tpl b/com.woltlab.wcf/templates/__iconFormField.tpl index 033ea6b609..fe3cecf0a4 100644 --- a/com.woltlab.wcf/templates/__iconFormField.tpl +++ b/com.woltlab.wcf/templates/__iconFormField.tpl @@ -1,28 +1,32 @@ {include file='__formFieldHeader'} getValue()} class="icon icon64 fa-{$field->getValue()}"{/if} id="{@$field->getPrefixedId()}_icon"> -{lang}wcf.global.button.edit{/lang} - - -{if $__iconFormFieldIncludeJavaScript} - {include file='fontAwesomeJavaScript'} +{if !$field->isImmutable()} + {lang}wcf.global.button.edit{/lang} {/if} + - + +{/if} {include file='__formFieldFooter'} diff --git a/com.woltlab.wcf/templates/__multipleSelectionFormField.tpl b/com.woltlab.wcf/templates/__multipleSelectionFormField.tpl index 5f531d6940..8920cbb2e3 100644 --- a/com.woltlab.wcf/templates/__multipleSelectionFormField.tpl +++ b/com.woltlab.wcf/templates/__multipleSelectionFormField.tpl @@ -20,12 +20,18 @@ {else} - {htmlCheckboxes options=$field->getOptions() name=$field->getPrefixedId() selected=$field->getValue() disableEncoding=true} + {htmlCheckboxes options=$field->getOptions() name=$field->getPrefixedId() selected=$field->getValue() disabled=$field->isImmutable() disableEncoding=true} {/if} {include file='__formFieldFooter'} diff --git a/com.woltlab.wcf/templates/__singleSelectionFormField.tpl b/com.woltlab.wcf/templates/__singleSelectionFormField.tpl index e54da20a28..f772ab7b03 100644 --- a/com.woltlab.wcf/templates/__singleSelectionFormField.tpl +++ b/com.woltlab.wcf/templates/__singleSelectionFormField.tpl @@ -20,14 +20,25 @@ {else} {/if} diff --git a/wcfsetup/install/files/acp/templates/__iconFormField.tpl b/wcfsetup/install/files/acp/templates/__iconFormField.tpl index 033ea6b609..fe3cecf0a4 100644 --- a/wcfsetup/install/files/acp/templates/__iconFormField.tpl +++ b/wcfsetup/install/files/acp/templates/__iconFormField.tpl @@ -1,28 +1,32 @@ {include file='__formFieldHeader'} getValue()} class="icon icon64 fa-{$field->getValue()}"{/if} id="{@$field->getPrefixedId()}_icon"> -{lang}wcf.global.button.edit{/lang} - - -{if $__iconFormFieldIncludeJavaScript} - {include file='fontAwesomeJavaScript'} +{if !$field->isImmutable()} + {lang}wcf.global.button.edit{/lang} {/if} + - + +{/if} {include file='__formFieldFooter'} diff --git a/wcfsetup/install/files/acp/templates/__multipleSelectionFormField.tpl b/wcfsetup/install/files/acp/templates/__multipleSelectionFormField.tpl index 5f531d6940..8920cbb2e3 100644 --- a/wcfsetup/install/files/acp/templates/__multipleSelectionFormField.tpl +++ b/wcfsetup/install/files/acp/templates/__multipleSelectionFormField.tpl @@ -20,12 +20,18 @@
    {foreach from=$field->getNestedOptions() item=__fieldNestedOption} 0} style="padding-left: {$__fieldNestedOption[depth]*20}px"{/if}> - + {/foreach}
{else} - {htmlCheckboxes options=$field->getOptions() name=$field->getPrefixedId() selected=$field->getValue() disableEncoding=true} + {htmlCheckboxes options=$field->getOptions() name=$field->getPrefixedId() selected=$field->getValue() disabled=$field->isImmutable() disableEncoding=true} {/if} {include file='__formFieldFooter'} diff --git a/wcfsetup/install/files/acp/templates/__singleSelectionFormField.tpl b/wcfsetup/install/files/acp/templates/__singleSelectionFormField.tpl index e54da20a28..f772ab7b03 100644 --- a/wcfsetup/install/files/acp/templates/__singleSelectionFormField.tpl +++ b/wcfsetup/install/files/acp/templates/__singleSelectionFormField.tpl @@ -20,14 +20,25 @@
    {foreach from=$field->getNestedOptions() item=__fieldNestedOption} 0} style="padding-left: {$__fieldNestedOption[depth]*20}px"{/if}> - + {/foreach}
{else} {/if} 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 0bbae157e4..5583b02038 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 @@ -27,12 +27,6 @@ abstract class AbstractFormField implements IFormField { */ protected $__autoFocus = false; - /** - * `true` if the value of this field is immutable and `false` otherwise - * @var bool - */ - protected $__immutable = false; - /** * name of the object property this field represents * @var null|string @@ -179,15 +173,6 @@ abstract class AbstractFormField implements IFormField { return true; } - /** - * @inheritDoc - */ - public function immutable($immutable = true) { - $this->__immutable = $immutable; - - return $this; - } - /** * @inheritDoc */ @@ -195,13 +180,6 @@ abstract class AbstractFormField implements IFormField { return $this->__autoFocus; } - /** - * @inheritDoc - */ - public function isImmutable() { - return $this->__immutable; - } - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/form/builder/field/AbstractNumericFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/AbstractNumericFormField.class.php index d0ac5b883f..8e4837f44b 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/AbstractNumericFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/AbstractNumericFormField.class.php @@ -11,7 +11,8 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -abstract class AbstractNumericFormField extends AbstractFormField implements IMaximumFormField, IMinimumFormField, INullableFormField, IPlaceholderFormField, ISuffixedFormField { +abstract class AbstractNumericFormField extends AbstractFormField implements IImmutableFormField, IMaximumFormField, IMinimumFormField, INullableFormField, IPlaceholderFormField, ISuffixedFormField { + use TImmutableFormField; use TMaximumFormField; use TMinimumFormField; use TNullableFormField; diff --git a/wcfsetup/install/files/lib/system/form/builder/field/BooleanFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/BooleanFormField.class.php index df3095f55c..b277eea8fd 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/BooleanFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/BooleanFormField.class.php @@ -11,7 +11,9 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class BooleanFormField extends AbstractFormField { +class BooleanFormField extends AbstractFormField implements IImmutableFormField { + use TImmutableFormField; + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php index c8e599a11c..bee9fb5cf0 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php @@ -11,7 +11,9 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class DateFormField extends AbstractFormField { +class DateFormField extends AbstractFormField implements IImmutableFormField { + use TImmutableFormField; + /** * date time format of the save value * @var string diff --git a/wcfsetup/install/files/lib/system/form/builder/field/IFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/IFormField.class.php index 0273d144d4..be0f98a303 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/IFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/IFormField.class.php @@ -107,14 +107,6 @@ interface IFormField extends IFormChildNode, IFormElement { */ public function hasSaveValue(); - /** - * Sets whether the value of this field is immutable and returns this field. - * - * @param bool $immutable determines if field value is immutable - * @return static this field - */ - public function immutable($immutable = true); - /** * Returns `true` if this field is auto-focused and returns `false` otherwise. * By default, fields are not auto-focused. @@ -123,14 +115,6 @@ interface IFormField extends IFormChildNode, IFormElement { */ public function isAutoFocused(); - /** - * Returns `true` if the value of this field is immutable and returns `false` - * otherwise. By default, fields are mutable. - * - * @return bool - */ - public function isImmutable(); - /** * Returns `true` if this field has to be filled out and returns `false` otherwise. * By default, fields do not have to be filled out. diff --git a/wcfsetup/install/files/lib/system/form/builder/field/IImmutableFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/IImmutableFormField.class.php new file mode 100644 index 0000000000..211283cc02 --- /dev/null +++ b/wcfsetup/install/files/lib/system/form/builder/field/IImmutableFormField.class.php @@ -0,0 +1,29 @@ + + * @package WoltLabSuite\Core\System\Form\Builder\Field + * @since 5.2 + */ +interface IImmutableFormField { + /** + * Sets whether the value of this field is immutable and returns this field. + * + * @param bool $immutable determines if field value is immutable + * @return static this field + */ + public function immutable($immutable = true); + + /** + * Returns `true` if the value of this field is immutable and returns `false` + * otherwise. By default, fields are mutable. + * + * @return bool + */ + public function isImmutable(); +} diff --git a/wcfsetup/install/files/lib/system/form/builder/field/IconFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/IconFormField.class.php index ceea8cbf99..88d178885b 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/IconFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/IconFormField.class.php @@ -12,7 +12,9 @@ use wcf\system\style\StyleHandler; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class IconFormField extends AbstractFormField { +class IconFormField extends AbstractFormField implements IImmutableFormField { + use TImmutableFormField; + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/form/builder/field/ItemListFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/ItemListFormField.class.php index 8792186158..978e2aa8bb 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/ItemListFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/ItemListFormField.class.php @@ -14,7 +14,9 @@ use wcf\util\ArrayUtil; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class ItemListFormField extends AbstractFormField { +class ItemListFormField extends AbstractFormField implements IImmutableFormField { + use TImmutableFormField; + /** * type of the returned save value (see `SAVE_VALUE_TYPE_*` constants) * @var string diff --git a/wcfsetup/install/files/lib/system/form/builder/field/MultipleSelectionFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/MultipleSelectionFormField.class.php index abc58ae2fb..06aa215e9d 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/MultipleSelectionFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/MultipleSelectionFormField.class.php @@ -11,8 +11,9 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class MultipleSelectionFormField extends AbstractFormField implements IFilterableSelectionFormField, INullableFormField { +class MultipleSelectionFormField extends AbstractFormField implements IFilterableSelectionFormField, IImmutableFormField, INullableFormField { use TFilterableSelectionFormField; + use TImmutableFormField; use TNullableFormField; /** diff --git a/wcfsetup/install/files/lib/system/form/builder/field/RadioButtonFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/RadioButtonFormField.class.php index 2a982b4e68..ca211a5fdd 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/RadioButtonFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/RadioButtonFormField.class.php @@ -11,7 +11,8 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class RadioButtonFormField extends AbstractFormField implements ISelectionFormField { +class RadioButtonFormField extends AbstractFormField implements IImmutableFormField, ISelectionFormField { + use TImmutableFormField; use TSelectionFormField; /** diff --git a/wcfsetup/install/files/lib/system/form/builder/field/SingleSelectionFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/SingleSelectionFormField.class.php index 5e5e5be7f1..82c73ac70d 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/SingleSelectionFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/SingleSelectionFormField.class.php @@ -11,7 +11,8 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class SingleSelectionFormField extends AbstractFormField implements IFilterableSelectionFormField, INullableFormField { +class SingleSelectionFormField extends AbstractFormField implements IImmutableFormField, IFilterableSelectionFormField, INullableFormField { + use TImmutableFormField; use TFilterableSelectionFormField; use TNullableFormField; diff --git a/wcfsetup/install/files/lib/system/form/builder/field/TImmutableFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/TImmutableFormField.class.php new file mode 100644 index 0000000000..e93c5d279c --- /dev/null +++ b/wcfsetup/install/files/lib/system/form/builder/field/TImmutableFormField.class.php @@ -0,0 +1,41 @@ + + * @package WoltLabSuite\Core\System\Form\Builder\Field + * @since 5.2 + */ +trait TImmutableFormField { + /** + * `true` if the value of this field is immutable and `false` otherwise + * @var bool + */ + protected $__immutable = false; + + /** + * Sets whether the value of this field is immutable and returns this field. + * + * @param bool $immutable determines if field value is immutable + * @return static this field + */ + public function immutable($immutable = true) { + $this->__immutable = $immutable; + + return $this; + } + + /** + * Returns `true` if the value of this field is immutable and returns `false` + * otherwise. By default, fields are mutable. + * + * @return bool + */ + public function isImmutable() { + return $this->__immutable; + } +} \ No newline at end of file diff --git a/wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php index db99e85110..ab303eb3cb 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php @@ -13,7 +13,8 @@ use wcf\system\language\LanguageFactory; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class TextFormField extends AbstractFormField implements II18nFormField, IMaximumLengthFormField, IMinimumLengthFormField, IPlaceholderFormField { +class TextFormField extends AbstractFormField implements II18nFormField, IImmutableFormField, IMaximumLengthFormField, IMinimumLengthFormField, IPlaceholderFormField { + use TImmutableFormField; use TI18nFormField { validate as protected i18nValidate; } diff --git a/wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php index 12b1b0d46a..18f67e8f55 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php @@ -2,8 +2,10 @@ namespace wcf\system\form\builder\field\user; use wcf\data\user\UserProfile; use wcf\system\form\builder\field\AbstractFormField; +use wcf\system\form\builder\field\IImmutableFormField; use wcf\system\form\builder\field\IMultipleFormField; use wcf\system\form\builder\field\INullableFormField; +use wcf\system\form\builder\field\TImmutableFormField; use wcf\system\form\builder\field\TMultipleFormField; use wcf\system\form\builder\field\TNullableFormField; use wcf\system\form\builder\field\validation\FormFieldValidationError; @@ -19,7 +21,8 @@ use wcf\util\StringUtil; * @package WoltLabSuite\Core\System\Form\Builder\Field\User * @since 5.2 */ -class UserFormField extends AbstractFormField implements IMultipleFormField, INullableFormField { +class UserFormField extends AbstractFormField implements IImmutableFormField, IMultipleFormField, INullableFormField { + use TImmutableFormField; use TMultipleFormField; use TNullableFormField; diff --git a/wcfsetup/install/files/lib/system/form/builder/field/user/UsernameFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/user/UsernameFormField.class.php index 8a55626555..8e2b298a82 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/user/UsernameFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/user/UsernameFormField.class.php @@ -1,10 +1,12 @@