Add `UrlFormField`
authorMatthias Schmidt <gravatronics@live.com>
Sun, 9 Dec 2018 08:17:00 +0000 (09:17 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 9 Dec 2018 08:17:00 +0000 (09:17 +0100)
See #2509

wcfsetup/install/files/lib/system/form/builder/field/UrlFormField.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

diff --git a/wcfsetup/install/files/lib/system/form/builder/field/UrlFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/UrlFormField.class.php
new file mode 100644 (file)
index 0000000..ff49278
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+namespace wcf\system\form\builder\field;
+use wcf\data\language\Language;
+use wcf\system\form\builder\field\validation\FormFieldValidationError;
+use wcf\util\Url;
+
+/**
+ * Implementation of a form field to enter a url.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2018 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Form\Builder\Field
+ * @since      3.2
+ */
+class UrlFormField extends TextFormField {
+       /**
+        * @inheritDoc
+        */
+       protected function validateText($text, Language $language = null) {
+               if ($this->isRequired() && ($this->getValue() === null || $this->getValue() === '')) {
+                       if (!Url::is($text, FILTER_VALIDATE_URL)) {
+                               $this->addValidationError(new FormFieldValidationError(
+                                       'invalid',
+                                       'wcf.form.field.url.error.invalid',
+                                       ['language' => $language]
+                               ));
+                       }
+                       else {
+                               parent::validateText($text, $language);
+                       }
+               }
+       }
+}
index b1eb46428d55dc750b2decd77403c4e92071e71b..e8e50e904f7e93aecb57eeb86e476da6ce7501ce 100644 (file)
@@ -3162,6 +3162,7 @@ E-Mail-Adresse: {@$emailAddress} {* this line ends with a space *}
                <item name="wcf.form.field.userGroupOption.error.nonExistent"><![CDATA[Die folgenden Berechtigungen existieren nicht: {implode from=$options item=option}<code>{$option}</code>{/implode}.]]></item>
                <item name="wcf.form.field.username.error.invalid"><![CDATA[Der angegebene Benutzername ist ungültig.]]></item>
                <item name="wcf.form.field.username.error.notUnique"><![CDATA[Dieser Benutzername ist bereits vergeben.]]></item>
+               <item name="wcf.form.field.url.error.invalid"><![CDATA[Der angegebene Verweis ist ungültig.]]></item>
        </category>
        <category name="wcf.imageViewer">
                <item name="wcf.imageViewer.button.enlarge"><![CDATA[Vollbild-Modus]]></item>
index 727250221ec7baacbee370641f1ce762787abf08..228958bf58b3b286afe75c1c44c714c97b2c992c 100644 (file)
@@ -3536,6 +3536,7 @@ Email: {@$emailAddress} {* this line ends with a space *}
                <item name="wcf.form.field.username.error.invalid"><![CDATA[The entered username is invalid.]]></item>
                <item name="wcf.form.field.username.error.notUnique"><![CDATA[The entered username is already in use.]]></item>
                <item name="wcf.form.fieldValidator.dotSeparatedString.error.invalidSegments"><![CDATA[The following segments are invalid: {implode from=$invalidSegments key=segmentNumber item=segment}{if $segment !== ''}<code>{$segment}</code>{else}(empty){/if} (segment {#$segmentNumber + 1}){/implode}.]]></item>
+               <item name="wcf.form.field.url.error.invalid"><![CDATA[The entered link is invalid.]]></item>
        </category>
        <category name="wcf.imageViewer">
                <item name="wcf.imageViewer.button.enlarge"><![CDATA[Full Screen Mode]]></item>