Support wildcard for category name in `AclFormField` (#4355)
authorMatthias Schmidt <gravatronics@live.com>
Fri, 2 Jul 2021 08:37:30 +0000 (10:37 +0200)
committerGitHub <noreply@github.com>
Fri, 2 Jul 2021 08:37:30 +0000 (10:37 +0200)
wcfsetup/install/files/lib/system/form/builder/field/acl/AclFormField.class.php

index 3a6e4bea3cca37a4a2154477cdc74b32c36f830b..5f3337a485e2f9c3ea054687e6446a26f50555be 100644 (file)
@@ -57,6 +57,9 @@ class AclFormField extends AbstractFormField implements IObjectTypeFormNode
      * Sets the name of/filter for the name(s) of the shown acl option categories and
      * returns this field.
      *
+     * The category name supports a `.*` suffix for filtering by multiple categories,
+     * so that `user.*` matches all acl option categories beginning with `user.`, for example.
+     *
      * @param string $categoryName name of/filter for the acl option categories
      * @return  static      $this       this field
      *
@@ -64,7 +67,10 @@ class AclFormField extends AbstractFormField implements IObjectTypeFormNode
      */
     public function categoryName($categoryName)
     {
-        if (!\is_string($categoryName) || !\preg_match('~^[A-z0-9\-\_]+(\.[A-z0-9\-\_]+)+$~', $categoryName)) {
+        if (
+            !\is_string($categoryName)
+            || !\preg_match('~^[A-z0-9\-\_]+((\.[A-z0-9\-\_]+)+|(\.[A-z0-9\-\_]+)*?\.\*)$~', $categoryName)
+        ) {
             throw new \InvalidArgumentException("Invalid category name given for field '{$this->getId()}'.");
         }