From: Matthias Schmidt Date: Mon, 21 Dec 2020 18:16:55 +0000 (+0100) Subject: Add `TInputModeFormField` X-Git-Tag: 5.4.0_Alpha_1~520^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6f950e44b41923680bd2bf049c7f362b65efac27;p=GitHub%2FWoltLab%2FWCF.git Add `TInputModeFormField` --- diff --git a/wcfsetup/install/files/lib/system/form/builder/field/TInputModeFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/TInputModeFormField.class.php new file mode 100644 index 0000000000..600b3baa1e --- /dev/null +++ b/wcfsetup/install/files/lib/system/form/builder/field/TInputModeFormField.class.php @@ -0,0 +1,49 @@ + + * @package WoltLabSuite\Core\System\Form\Builder\Field + * @since 5.4 + */ +trait TInputModeFormField { + /** @var ?string */ + protected $inputMode; + + /** + * Returns the `inputmode` attribute of the form field. + * + * If `null` is returned, no `inputmode` attribute will be set. + */ + public function getInputMode(): ?string { + return $this->inputMode; + } + + /** + * Sets the `inputmode` attribute of the form field. + * + * If `null` is given, the attribute is unset. + * + * @throws \InvalidArgumentException if an invalid `inputmode` token is included in the attribute value + */ + public function inputMode(?string $inputMode): self { + if ($inputMode !== null && $inputMode !== 'none' && !in_array($inputMode, $this->getValidInputModes())) { + throw new \InvalidArgumentException("Invalid inputmode attribute '{$inputMode}'."); + } + + $this->inputMode = $inputMode; + + return $this; + } + + /** + * Returns all valid `inputmode` tokens. + */ + protected function getValidInputModes(): array { + return []; + } +}