Add RejectEverythingFormField
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 26 Jan 2021 14:22:28 +0000 (15:22 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 26 Jan 2021 14:33:20 +0000 (15:33 +0100)
wcfsetup/install/files/lib/system/form/builder/field/RejectEverythingFormField.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/form/builder/field/RejectEverythingFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/RejectEverythingFormField.class.php
new file mode 100644 (file)
index 0000000..0177553
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+namespace wcf\system\form\builder\field;
+
+use wcf\system\form\builder\field\validation\FormFieldValidationError;
+
+/**
+ * This form field always fails its validation.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 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
+ */
+final class RejectEverythingFormField extends AbstractFormField
+{
+    use TDefaultIdFormField;
+
+    /**
+     * @inheritDoc
+     */
+    public function getFieldHtml(): string
+    {
+        return '';
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getHtml(): string
+    {
+        return '';
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function readValue(): self
+    {
+        return $this;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function validate()
+    {
+        $this->addValidationError(new FormFieldValidationError('rejectEverything'));
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getSaveValue(): void
+    {
+        throw new \BadMethodCallException('This form field rejects everything.');
+    }
+
+    /**
+     * @inheritDoc
+     */
+    protected static function getDefaultId(): string
+    {
+        return 'rejectEverything';
+    }
+}