And add immutability support for some additional fields.
See #2509
{include file='__formFieldHeader'}
<span{if $field->getValue()} class="icon icon64 fa-{$field->getValue()}"{/if} id="{@$field->getPrefixedId()}_icon"></span>
-<a href="#" class="button small" id="{@$field->getPrefixedId()}_openIconDialog">{lang}wcf.global.button.edit{/lang}</a>
-<input type="hidden" id="{@$field->getPrefixedId()}" name="{@$field->getPrefixedId()}" value="{$field->getValue()}">
-
-{if $__iconFormFieldIncludeJavaScript}
- {include file='fontAwesomeJavaScript'}
+{if !$field->isImmutable()}
+ <a href="#" class="button small" id="{@$field->getPrefixedId()}_openIconDialog">{lang}wcf.global.button.edit{/lang}</a>
{/if}
+<input type="hidden" id="{@$field->getPrefixedId()}" name="{@$field->getPrefixedId()}" value="{$field->getValue()}">
-<script data-relocate="true">
- require(['WoltLabSuite/Core/Ui/Style/FontAwesome'], function(UiStyleFontAwesome) {
- var button = elById('{@$field->getPrefixedId()}_openIconDialog');
- var icon = elById('{@$field->getPrefixedId()}_icon');
- var input = elById('{@$field->getPrefixedId()}');
-
- var callback = function(iconName) {
- icon.className = 'icon icon64 fa-' + iconName;
- input.value = iconName;
- };
-
- button.addEventListener('click', function() {
- UiStyleFontAwesome.open(callback);
+{if !$field->isImmutable()}
+ {if $__iconFormFieldIncludeJavaScript}
+ {include file='fontAwesomeJavaScript'}
+ {/if}
+
+ <script data-relocate="true">
+ require(['WoltLabSuite/Core/Ui/Style/FontAwesome'], function(UiStyleFontAwesome) {
+ var button = elById('{@$field->getPrefixedId()}_openIconDialog');
+ var icon = elById('{@$field->getPrefixedId()}_icon');
+ var input = elById('{@$field->getPrefixedId()}');
+
+ var callback = function(iconName) {
+ icon.className = 'icon icon64 fa-' + iconName;
+ input.value = iconName;
+ };
+
+ button.addEventListener('click', function() {
+ UiStyleFontAwesome.open(callback);
+ });
});
- });
-</script>
+ </script>
+{/if}
{include file='__formFieldFooter'}
<ul class="scrollableCheckboxList" id="{@$field->getPrefixedId()}_list">
{foreach from=$field->getNestedOptions() item=__fieldNestedOption}
<li{if $__fieldNestedOption[depth] > 0} style="padding-left: {$__fieldNestedOption[depth]*20}px"{/if}>
- <label><input type="checkbox" name="{@$field->getPrefixedId()}[]" value="{$__fieldNestedOption[value]}"{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue()} checked{/if}> {@$__fieldNestedOption[label]}</label>
+ <label><input {*
+ *}type="checkbox" {*
+ *}name="{@$field->getPrefixedId()}[]" {*
+ *}value="{$__fieldNestedOption[value]}"{*
+ *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue()} checked{/if}{*
+ *}{if $field->isImmutable()} disabled{/if}{*
+ *}> {@$__fieldNestedOption[label]}</label>
</li>
{/foreach}
</ul>
{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'}
<ul class="scrollableCheckboxList" id="{@$field->getPrefixedId()}_list">
{foreach from=$field->getNestedOptions() item=__fieldNestedOption}
<li{if $__fieldNestedOption[depth] > 0} style="padding-left: {$__fieldNestedOption[depth]*20}px"{/if}>
- <label><input type="radio" name="{@$field->getPrefixedId()}" value="{$__fieldNestedOption[value]}"{if $field->getValue() == $__fieldNestedOption[value]} checked{/if}> {@$__fieldNestedOption[label]}</label>
+ <label><input {*
+ *}type="radio" {*
+ *}name="{@$field->getPrefixedId()}" {*
+ *}value="{$__fieldNestedOption[value]}"{*
+ *}{if $field->getValue() == $__fieldNestedOption[value]} checked{/if}{*
+ *}{if $field->isImmutable()} disabled{/if}{*
+ *}> {@$__fieldNestedOption[label]}</label>
</li>
{/foreach}
</ul>
{else}
<select id="{@$field->getPrefixedId()}" name="{@$field->getPrefixedId()}">
{foreach from=$field->getNestedOptions() item=__fieldNestedOption}
- <option name="{@$field->getPrefixedId()}" value="{$__fieldNestedOption[value]}"{if $field->getValue() == $__fieldNestedOption[value]} selected{/if}>{@' '|str_repeat:$__fieldNestedOption[depth] * 4}{@$__fieldNestedOption[label]}</option>
+ <option {*
+ *}name="{@$field->getPrefixedId()}" {*
+ *}value="{$__fieldNestedOption[value]}"{*
+ *}{if $field->getValue() == $__fieldNestedOption[value]} selected{/if}{*
+ *}{if $field->isImmutable()} disabled{/if}{*
+ *}>{@' '|str_repeat:$__fieldNestedOption[depth] * 4}{@$__fieldNestedOption[label]}</option>
{/foreach}
</select>
{/if}
{include file='__formFieldHeader'}
<span{if $field->getValue()} class="icon icon64 fa-{$field->getValue()}"{/if} id="{@$field->getPrefixedId()}_icon"></span>
-<a href="#" class="button small" id="{@$field->getPrefixedId()}_openIconDialog">{lang}wcf.global.button.edit{/lang}</a>
-<input type="hidden" id="{@$field->getPrefixedId()}" name="{@$field->getPrefixedId()}" value="{$field->getValue()}">
-
-{if $__iconFormFieldIncludeJavaScript}
- {include file='fontAwesomeJavaScript'}
+{if !$field->isImmutable()}
+ <a href="#" class="button small" id="{@$field->getPrefixedId()}_openIconDialog">{lang}wcf.global.button.edit{/lang}</a>
{/if}
+<input type="hidden" id="{@$field->getPrefixedId()}" name="{@$field->getPrefixedId()}" value="{$field->getValue()}">
-<script data-relocate="true">
- require(['WoltLabSuite/Core/Ui/Style/FontAwesome'], function(UiStyleFontAwesome) {
- var button = elById('{@$field->getPrefixedId()}_openIconDialog');
- var icon = elById('{@$field->getPrefixedId()}_icon');
- var input = elById('{@$field->getPrefixedId()}');
-
- var callback = function(iconName) {
- icon.className = 'icon icon64 fa-' + iconName;
- input.value = iconName;
- };
-
- button.addEventListener('click', function() {
- UiStyleFontAwesome.open(callback);
+{if !$field->isImmutable()}
+ {if $__iconFormFieldIncludeJavaScript}
+ {include file='fontAwesomeJavaScript'}
+ {/if}
+
+ <script data-relocate="true">
+ require(['WoltLabSuite/Core/Ui/Style/FontAwesome'], function(UiStyleFontAwesome) {
+ var button = elById('{@$field->getPrefixedId()}_openIconDialog');
+ var icon = elById('{@$field->getPrefixedId()}_icon');
+ var input = elById('{@$field->getPrefixedId()}');
+
+ var callback = function(iconName) {
+ icon.className = 'icon icon64 fa-' + iconName;
+ input.value = iconName;
+ };
+
+ button.addEventListener('click', function() {
+ UiStyleFontAwesome.open(callback);
+ });
});
- });
-</script>
+ </script>
+{/if}
{include file='__formFieldFooter'}
<ul class="scrollableCheckboxList" id="{@$field->getPrefixedId()}_list">
{foreach from=$field->getNestedOptions() item=__fieldNestedOption}
<li{if $__fieldNestedOption[depth] > 0} style="padding-left: {$__fieldNestedOption[depth]*20}px"{/if}>
- <label><input type="checkbox" name="{@$field->getPrefixedId()}[]" value="{$__fieldNestedOption[value]}"{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue()} checked{/if}> {@$__fieldNestedOption[label]}</label>
+ <label><input {*
+ *}type="checkbox" {*
+ *}name="{@$field->getPrefixedId()}[]" {*
+ *}value="{$__fieldNestedOption[value]}"{*
+ *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue()} checked{/if}{*
+ *}{if $field->isImmutable()} disabled{/if}{*
+ *}> {@$__fieldNestedOption[label]}</label>
</li>
{/foreach}
</ul>
{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'}
<ul class="scrollableCheckboxList" id="{@$field->getPrefixedId()}_list">
{foreach from=$field->getNestedOptions() item=__fieldNestedOption}
<li{if $__fieldNestedOption[depth] > 0} style="padding-left: {$__fieldNestedOption[depth]*20}px"{/if}>
- <label><input type="radio" name="{@$field->getPrefixedId()}" value="{$__fieldNestedOption[value]}"{if $field->getValue() == $__fieldNestedOption[value]} checked{/if}> {@$__fieldNestedOption[label]}</label>
+ <label><input {*
+ *}type="radio" {*
+ *}name="{@$field->getPrefixedId()}" {*
+ *}value="{$__fieldNestedOption[value]}"{*
+ *}{if $field->getValue() == $__fieldNestedOption[value]} checked{/if}{*
+ *}{if $field->isImmutable()} disabled{/if}{*
+ *}> {@$__fieldNestedOption[label]}</label>
</li>
{/foreach}
</ul>
{else}
<select id="{@$field->getPrefixedId()}" name="{@$field->getPrefixedId()}">
{foreach from=$field->getNestedOptions() item=__fieldNestedOption}
- <option name="{@$field->getPrefixedId()}" value="{$__fieldNestedOption[value]}"{if $field->getValue() == $__fieldNestedOption[value]} selected{/if}>{@' '|str_repeat:$__fieldNestedOption[depth] * 4}{@$__fieldNestedOption[label]}</option>
+ <option {*
+ *}name="{@$field->getPrefixedId()}" {*
+ *}value="{$__fieldNestedOption[value]}"{*
+ *}{if $field->getValue() == $__fieldNestedOption[value]} selected{/if}{*
+ *}{if $field->isImmutable()} disabled{/if}{*
+ *}>{@' '|str_repeat:$__fieldNestedOption[depth] * 4}{@$__fieldNestedOption[label]}</option>
{/foreach}
</select>
{/if}
*/
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
return true;
}
- /**
- * @inheritDoc
- */
- public function immutable($immutable = true) {
- $this->__immutable = $immutable;
-
- return $this;
- }
-
/**
* @inheritDoc
*/
return $this->__autoFocus;
}
- /**
- * @inheritDoc
- */
- public function isImmutable() {
- return $this->__immutable;
- }
-
/**
* @inheritDoc
*/
* @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;
* @package WoltLabSuite\Core\System\Form\Builder\Field
* @since 5.2
*/
-class BooleanFormField extends AbstractFormField {
+class BooleanFormField extends AbstractFormField implements IImmutableFormField {
+ use TImmutableFormField;
+
/**
* @inheritDoc
*/
* @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
*/
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.
*/
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.
--- /dev/null
+<?php
+namespace wcf\system\form\builder\field;
+
+/**
+ * Represents a form field that can be set as immutable.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2018 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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();
+}
* @package WoltLabSuite\Core\System\Form\Builder\Field
* @since 5.2
*/
-class IconFormField extends AbstractFormField {
+class IconFormField extends AbstractFormField implements IImmutableFormField {
+ use TImmutableFormField;
+
/**
* @inheritDoc
*/
* @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
* @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;
/**
* @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;
/**
* @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;
--- /dev/null
+<?php
+namespace wcf\system\form\builder\field;
+
+/**
+ * Provides default implementations of `IImmutableFormField` methods.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2018 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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
* @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;
}
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;
* @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;
<?php
namespace wcf\system\form\builder\field\user;
use wcf\system\form\builder\field\AbstractFormField;
+use wcf\system\form\builder\field\IImmutableFormField;
use wcf\system\form\builder\field\IMaximumLengthFormField;
use wcf\system\form\builder\field\IMinimumLengthFormField;
use wcf\system\form\builder\field\INullableFormField;
use wcf\system\form\builder\field\IPlaceholderFormField;
+use wcf\system\form\builder\field\TImmutableFormField;
use wcf\system\form\builder\field\TMaximumLengthFormField;
use wcf\system\form\builder\field\TMinimumLengthFormField;
use wcf\system\form\builder\field\TNullableFormField;
* @package WoltLabSuite\Core\System\Form\Builder\Field\User
* @since 5.2
*/
-class UsernameFormField extends AbstractFormField implements IMaximumLengthFormField, IMinimumLengthFormField, INullableFormField, IPlaceholderFormField {
+class UsernameFormField extends AbstractFormField implements IImmutableFormField, IMaximumLengthFormField, IMinimumLengthFormField, INullableFormField, IPlaceholderFormField {
+ use TImmutableFormField;
use TMaximumLengthFormField;
use TMinimumLengthFormField;
use TNullableFormField;