Add `TInputModeFormField`
authorMatthias Schmidt <gravatronics@live.com>
Mon, 21 Dec 2020 18:16:55 +0000 (19:16 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 21 Dec 2020 18:16:55 +0000 (19:16 +0100)
wcfsetup/install/files/lib/system/form/builder/field/TInputModeFormField.class.php [new file with mode: 0644]

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 (file)
index 0000000..600b3ba
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+namespace wcf\system\form\builder\field;
+
+/**
+ * Provides default implementations of `IInputModeFormField` methods.
+ *
+ * @author      Matthias Schmidt
+ * @copyright   2001-2020 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 [];
+       }
+}