From 66b15af49b8b9ed90ac3dc55bdfeacbcf64de8ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 12 Feb 2021 12:07:11 +0100 Subject: [PATCH] Add option name validators to devtools form for the `option` PIP see #3966 --- .../OptionPackageInstallationPlugin.class.php | 28 +++++++++++++++++++ wcfsetup/install/lang/de.xml | 2 ++ wcfsetup/install/lang/en.xml | 2 ++ 3 files changed, 32 insertions(+) diff --git a/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php index 75b1ea4462..b131ea5b17 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php @@ -223,6 +223,34 @@ class OptionPackageInstallationPlugin extends AbstractOptionPackageInstallationP } } )); + $optionNameField->addValidator(new FormFieldValidator( + 'lowercase', + static function (TextFormField $formField) { + $value = $formField->getValue(); + if ($value !== \strtolower($value)) { + $formField->addValidationError( + new FormFieldValidationError( + 'notLowercase', + 'wcf.acp.pip.option.optionName.error.notLowercase' + ) + ); + } + } + )); + $optionNameField->addValidator(new FormFieldValidator( + 'pattern', + static function (TextFormField $formField) { + $value = $formField->getValue(); + if (!\preg_match('/^[a-z][a-z0-9_]*[a-z]$/', $value)) { + $formField->addValidationError( + new FormFieldValidationError( + 'pattern', + 'wcf.acp.pip.option.optionName.error.pattern' + ) + ); + } + } + )); // add `hidden` pseudo-category /** @var SingleSelectionFormField $categoryName */ diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index f3237fbfc7..f8f6839362 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2616,6 +2616,8 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen userProfileMenu-Package Installation Plugin installiert neue Menüpunkte für das Benutzerprofilmenü. {if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} mehr Informationen in der Entwickler-Dokumentation finden.]]> {literal}{if LANGUAGE_USE_INFORMAL_VARIANT}{else}{/if}{/literal}, „“]]> “”]]> + + {$reactionType->getTitle()} wirklich löschen?]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index f0814b1533..0aa9518921 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2544,6 +2544,8 @@ If you have already bought the licenses for the listed apps, th userProfileMenu package installation plugin installs new menu items for the user profile menu. You can find more information in the developer documentation.]]> {literal}{if LANGUAGE_USE_INFORMAL_VARIANT}{else}{/if}{/literal}, „“]]> “”]]> + + {$reactionType->getTitle()}?]]> -- 2.20.1