From: Matthias Schmidt Date: Sun, 10 Mar 2019 09:04:33 +0000 (+0100) Subject: Move form field auto-focus to dedicated interface/trait X-Git-Tag: 5.2.0_Alpha_1~233^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=faac87fb32bc6a173f0a9629fa3e49b50a68e513;p=GitHub%2FWoltLab%2FWCF.git Move form field auto-focus to dedicated interface/trait See #2509 --- 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 7967a1443e..3255efde56 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 @@ -21,12 +21,6 @@ abstract class AbstractFormField implements IFormField { use TFormChildNode; use TFormElement; - /** - * `true` if this field is auto-focused and `false` otherwise - * @var bool - */ - protected $autoFocus = false; - /** * name of the object property this field represents * @var null|string @@ -89,15 +83,6 @@ abstract class AbstractFormField implements IFormField { return $this; } - /** - * @inheritDoc - */ - public function autoFocus($autoFocus = true) { - $this->autoFocus = $autoFocus; - - return $this; - } - /** * @inheritDoc */ @@ -173,13 +158,6 @@ abstract class AbstractFormField implements IFormField { return true; } - /** - * @inheritDoc - */ - public function isAutoFocused() { - return $this->autoFocus; - } - /** * @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 7533f5502c..b6031142b0 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 IImmutableFormField, IMaximumFormField, IMinimumFormField, INullableFormField, IPlaceholderFormField, ISuffixedFormField { +abstract class AbstractNumericFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField, IMaximumFormField, IMinimumFormField, INullableFormField, IPlaceholderFormField, ISuffixedFormField { + use TAutoFocusFormField; use TImmutableFormField; use TMaximumFormField; use TMinimumFormField; 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 8e9266a54a..0c5d6f280f 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,8 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class BooleanFormField extends AbstractFormField implements IImmutableFormField { +class BooleanFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField { + use TAutoFocusFormField; use TImmutableFormField; /** 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 147cf711d2..13c13e6244 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 @@ -12,7 +12,8 @@ use wcf\util\DateUtil; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class DateFormField extends AbstractFormField implements IImmutableFormField, INullableFormField { +class DateFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField, INullableFormField { + use TAutoFocusFormField; use TImmutableFormField; use TNullableFormField; diff --git a/wcfsetup/install/files/lib/system/form/builder/field/IAutoFocusFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/IAutoFocusFormField.class.php new file mode 100644 index 0000000000..43ecca74a2 --- /dev/null +++ b/wcfsetup/install/files/lib/system/form/builder/field/IAutoFocusFormField.class.php @@ -0,0 +1,30 @@ + + * @package WoltLabSuite\Core\System\Form\Builder\Field + * @since 5.2 + */ +interface IAutoFocusFormField { + /** + * Sets whether this field is auto-focused and returns this field. + * + * @param bool $autoFocus determines if field is auto-focused + * @return static this field + */ + public function autoFocus($autoFocus = true); + + /** + * Returns `true` if this field is auto-focused and returns `false` otherwise. + * + * By default, fields are not auto-focused. + * + * @return bool + */ + public function isAutoFocused(); +} 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 0e8b7f7a71..ecdf166a46 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 @@ -24,13 +24,7 @@ interface IFormField extends IFormChildNode, IFormElement { */ public function addValidationError(IFormFieldValidationError $error); - /** - * Sets whether this field is auto-focused and returns this field. - * - * @param bool $autoFocus determines if field is auto-focused - * @return static this field - */ - public function autoFocus($autoFocus = true); + /** * Adds the given validation error to this field and returns this field. @@ -107,14 +101,6 @@ interface IFormField extends IFormChildNode, IFormElement { */ public function hasSaveValue(); - /** - * Returns `true` if this field is auto-focused and returns `false` otherwise. - * By default, fields are not auto-focused. - * - * @return bool - */ - public function isAutoFocused(); - /** * 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/ItemListFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/ItemListFormField.class.php index d2d47f20c3..f0d7e5e03e 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,8 @@ use wcf\util\ArrayUtil; * @package WoltLabSuite\Core\System\Form\Builder\Field * @since 5.2 */ -class ItemListFormField extends AbstractFormField implements IImmutableFormField { +class ItemListFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField { + use TAutoFocusFormField; use TImmutableFormField; /** diff --git a/wcfsetup/install/files/lib/system/form/builder/field/TAutoFocusFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/TAutoFocusFormField.class.php new file mode 100644 index 0000000000..f1e59d28d0 --- /dev/null +++ b/wcfsetup/install/files/lib/system/form/builder/field/TAutoFocusFormField.class.php @@ -0,0 +1,42 @@ + + * @package WoltLabSuite\Core\System\Form\Builder\Field + * @since 5.2 + */ +trait TAutoFocusFormField { + /** + * `true` if this field is auto-focused and `false` otherwise + * @var bool + */ + protected $autoFocus = false; + + /** + * Sets whether this field is auto-focused and returns this field. + * + * @param bool $autoFocus determines if field is auto-focused + * @return static this field + */ + public function autoFocus($autoFocus = true) { + $this->autoFocus = $autoFocus; + + return $this; + } + + /** + * Returns `true` if this field is auto-focused and returns `false` otherwise. + * + * By default, fields are not auto-focused. + * + * @return bool + */ + public function isAutoFocused() { + return $this->autoFocus; + } +} \ 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 1e9bc86b2d..39d4321909 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, IImmutableFormField, IMaximumLengthFormField, IMinimumLengthFormField, IPlaceholderFormField { +class TextFormField extends AbstractFormField implements IAutoFocusFormField, II18nFormField, IImmutableFormField, IMaximumLengthFormField, IMinimumLengthFormField, IPlaceholderFormField { + use TAutoFocusFormField; 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 ee3db32383..7950deb002 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,9 +2,11 @@ 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\IAutoFocusFormField; 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\TAutoFocusFormField; use wcf\system\form\builder\field\TImmutableFormField; use wcf\system\form\builder\field\TMultipleFormField; use wcf\system\form\builder\field\TNullableFormField; @@ -21,7 +23,8 @@ use wcf\util\StringUtil; * @package WoltLabSuite\Core\System\Form\Builder\Field\User * @since 5.2 */ -class UserFormField extends AbstractFormField implements IImmutableFormField, IMultipleFormField, INullableFormField { +class UserFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField, IMultipleFormField, INullableFormField { + use TAutoFocusFormField; 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 95ca23c712..a45ecc4023 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,11 +1,13 @@