From 6f950e44b41923680bd2bf049c7f362b65efac27 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 21 Dec 2020 19:16:55 +0100 Subject: [PATCH] Add `TInputModeFormField` --- .../field/TInputModeFormField.class.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/form/builder/field/TInputModeFormField.class.php 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 []; + } +} -- 2.20.1