Merge branch '5.3'
authorMatthias Schmidt <gravatronics@live.com>
Tue, 9 Mar 2021 15:33:21 +0000 (16:33 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 9 Mar 2021 15:34:01 +0000 (16:34 +0100)
1  2 
ts/WoltLabSuite/Core/Form/Builder/Field/User.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/User.js
wcfsetup/install/files/lib/system/form/builder/field/acl/AclFormField.class.php

index 03cb752b1903b08a1da4224f890396d19ae450f1,0000000000000000000000000000000000000000..626300d81be186911fb8644fe890fe63d0792471
mode 100644,000000..100644
--- /dev/null
@@@ -1,36 -1,0 +1,28 @@@
-     const usernames = UiItemList.getValues(this._fieldId)
-       .map((item) => {
-         if (item.objectId) {
-           return item.value;
-         }
-         return null;
-       })
-       .filter((v) => v !== null) as string[];
 +/**
 + * Data handler for a user form builder field in an Ajax form.
 + *
 + * @author  Matthias Schmidt
 + * @copyright 2001-2020 WoltLab GmbH
 + * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 + * @module  WoltLabSuite/Core/Form/Builder/Field/User
 + * @since 5.2
 + */
 +
 +import Field from "./Field";
 +import { FormBuilderData } from "../Data";
 +import * as Core from "../../../Core";
 +import * as UiItemList from "../../../Ui/ItemList";
 +
 +class User extends Field {
 +  protected _getData(): FormBuilderData {
++    const usernames = UiItemList.getValues(this._fieldId).map((item) => item.value);
 +
 +    return {
 +      [this._fieldId]: usernames.join(","),
 +    };
 +  }
 +}
 +
 +Core.enableLegacyInheritance(User);
 +
 +export = User;
index c1decaf495aa692107e1d595aa85fa25261fa1fb,9d50af5801f1991961f7ae3e168122626317d989..8e7b254088088908340a3811465580f041ef9e1a
@@@ -1,32 -1,38 +1,25 @@@
  /**
   * Data handler for a user form builder field in an Ajax form.
 - * 
 - * @author    Matthias Schmidt
 - * @copyright 2001-2019 WoltLab GmbH
 - * @license   GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 - * @module    WoltLabSuite/Core/Form/Builder/Field/User
 - * @since     5.2
 + *
 + * @author  Matthias Schmidt
 + * @copyright 2001-2020 WoltLab GmbH
 + * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 + * @module  WoltLabSuite/Core/Form/Builder/Field/User
 + * @since 5.2
   */
 -define(['Core', './Field', 'WoltLabSuite/Core/Ui/ItemList'], function(Core, FormBuilderField, UiItemList) {
 -      "use strict";
 -      
 -      /**
 -       * @constructor
 -       */
 -      function FormBuilderFieldUser(fieldId) {
 -              this.init(fieldId);
 -      };
 -      Core.inherit(FormBuilderFieldUser, FormBuilderField, {
 -              /**
 -               * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData
 -               */
 -              _getData: function() {
 -                      var values = UiItemList.getValues(this._fieldId);
 -                      var usernames = [];
 -                      for (var i = 0, length = values.length; i < length; i++) {
 -                              usernames.push(values[i].value);
 -                      }
 -                      
 -                      var data = {};
 -                      data[this._fieldId] = usernames.join(',');
 -                      
 -                      return data;
 -              }
 -      });
 -      
 -      return FormBuilderFieldUser;
 +define(["require", "exports", "tslib", "./Field", "../../../Core", "../../../Ui/ItemList"], function (require, exports, tslib_1, Field_1, Core, UiItemList) {
 +    "use strict";
 +    Field_1 = tslib_1.__importDefault(Field_1);
 +    Core = tslib_1.__importStar(Core);
 +    UiItemList = tslib_1.__importStar(UiItemList);
 +    class User extends Field_1.default {
 +        _getData() {
-             const usernames = UiItemList.getValues(this._fieldId)
-                 .map((item) => {
-                 if (item.objectId) {
-                     return item.value;
-                 }
-                 return null;
-             })
-                 .filter((v) => v !== null);
++            const usernames = UiItemList.getValues(this._fieldId).map((item) => item.value);
 +            return {
 +                [this._fieldId]: usernames.join(","),
 +            };
 +        }
 +    }
 +    Core.enableLegacyInheritance(User);
 +    return User;
  });
index ceaf4c3f9fd034b7fded1b7b75b7db2d19bcbb8f,317f9a8033d0bda313180fa66d5e5343140fce5a..b78e1b666ececf695b4a11557437b5269dcc0164
@@@ -12,174 -10,159 +12,174 @@@ use wcf\system\form\builder\TObjectType
  
  /**
   * Implementation of a form field for setting acl option values.
 - * 
 - * @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\Acl
 - * @since     5.2
 + *
 + * @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\Acl
 + * @since   5.2
   */
 -class AclFormField extends AbstractFormField implements IObjectTypeFormNode {
 -      use TObjectTypeFormNode;
 -      
 -      /**
 -       * name of/filter for the name(s) of the shown acl option categories
 -       * @var null|string
 -       */
 -      protected $categoryName;
 -      
 -      /**
 -       * @inheritDoc
 -       * @since       5.2.3
 -       */
 -      protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Acl';
 -      
 -      /**
 -       * id of the edited object or `null` if no object is edited
 -       * @var null|int
 -       */
 -      protected $objectID;
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      protected $templateName = '__aclFormField';
 -      
 -      /**
 -       * is `true` if acl-related global JavaScript code has already been included
 -       * and is `false` otherwise
 -       * @var bool
 -       */
 -      protected static $includedAclJavaScript = false;
 -      
 -      /**
 -       * Sets the name of/filter for the name(s) of the shown acl option categories and
 -       * returns this field.
 -       * 
 -       * @param       string          $categoryName   name of/filter for the acl option categories
 -       * @return      static          $this           this field
 -       * 
 -       * @throws      \InvalidArgumentException       if given category name is invalid
 -       */
 -      public function categoryName($categoryName) {
 -              if (!is_string($categoryName) || !preg_match('~^[A-z0-9\-\_]+(\.[A-z0-9\-\_]+)+$~', $categoryName)) {
 -                      throw new \InvalidArgumentException("Invalid category name given.");
 -              }
 -              
 -              $this->categoryName = $categoryName;
 -              
 -              return $this;
 -      }
 -      
 -      /**
 -       * Returns the name of/filter for the name(s) of the shown acl option categories
 -       * or returns `null` if no category name has been set.
 -       * 
 -       * @return      null|string
 -       */
 -      public function getCategoryName() {
 -              return $this->categoryName;
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function getHtmlVariables() {
 -              ACLHandler::getInstance()->assignVariables($this->getObjectType()->objectTypeID);
 -              
 -              $includeAclJavaScript = !static::$includedAclJavaScript;
 -              if (!static::$includedAclJavaScript) {
 -                      static::$includedAclJavaScript = true;
 -              }
 -              
 -              return [
 -                      'includeAclJavaScript' => $includeAclJavaScript
 -              ];
 -      }
 -      
 -      /**
 -       * Returns the id of the edited object or `null` if no object is edited.
 -       * 
 -       * @return      null|int
 -       */
 -      public function getObjectID() {
 -              return $this->objectID;
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function getObjectTypeDefinition() {
 -              return 'com.woltlab.wcf.acl';
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function hasSaveValue() {
 -              return false;
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function updatedObject(array $data, IStorableObject $object, $loadValues = true) {
 -              $this->objectID = $object->{$object::getDatabaseTableIndexName()};
 -              
 -              if ($this->objectID === null) {
 -                      throw new \UnexpectedValueException("Cannot read object id from object of class '" . get_class($object). "'.");
 -              }
 -              
 -              return $this;
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function populate() {
 -              parent::populate();
 -              
 -              $this->getDocument()->getDataHandler()->addProcessor(new CustomFormDataProcessor('acl', function(IFormDocument $document, array $parameters) {
 -                      $parameters[$this->getObjectProperty() . '_aclObjectTypeID'] = $this->getObjectType()->objectTypeID;
 -                      
 -                      return $parameters;
 -              }));
 -              
 -              return $this;
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function readValue() {
 -              $valueSource = $_POST[$this->getPrefixedId()] ?? [];
 -              if ($this->getDocument()->isAjax()) {
 -                      $valueSource = [];
 -                      if (
 -                              $this->getDocument()->hasRequestData($this->getPrefixedId())
 -                              && is_array($this->getDocument()->getRequestData($this->getPrefixedId()))
 -                      ) {
 -                              $valueSource = $this->getDocument()->getRequestData($this->getPrefixedId());
 -                      }
 -              }
 -              
 -              ACLHandler::getInstance()->readValues($this->getObjectType()->objectTypeID, $valueSource);
 -              
 -              return $this;
 -      }
 +class AclFormField extends AbstractFormField implements IObjectTypeFormNode
 +{
 +    use TObjectTypeFormNode;
 +
 +    /**
 +     * name of/filter for the name(s) of the shown acl option categories
 +     * @var null|string
 +     */
 +    protected $categoryName;
 +
 +    /**
 +     * @inheritDoc
 +     * @since   5.2.3
 +     */
 +    protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Acl';
 +
 +    /**
 +     * id of the edited object or `null` if no object is edited
 +     * @var null|int
 +     */
 +    protected $objectID;
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    protected $templateName = '__aclFormField';
 +
 +    /**
 +     * is `true` if acl-related global JavaScript code has already been included
 +     * and is `false` otherwise
 +     * @var bool
 +     */
 +    protected static $includedAclJavaScript = false;
 +
 +    /**
 +     * Sets the name of/filter for the name(s) of the shown acl option categories and
 +     * returns this field.
 +     *
 +     * @param string $categoryName name of/filter for the acl option categories
 +     * @return  static      $this       this field
 +     *
 +     * @throws  \InvalidArgumentException   if given category name is invalid
 +     */
 +    public function categoryName($categoryName)
 +    {
 +        if (!\is_string($categoryName) || !\preg_match('~^[A-z0-9\-\_]+(\.[A-z0-9\-\_]+)+$~', $categoryName)) {
 +            throw new \InvalidArgumentException("Invalid category name given.");
 +        }
 +
 +        $this->categoryName = $categoryName;
 +
 +        return $this;
 +    }
 +
 +    /**
 +     * Returns the name of/filter for the name(s) of the shown acl option categories
 +     * or returns `null` if no category name has been set.
 +     *
 +     * @return  null|string
 +     */
 +    public function getCategoryName()
 +    {
 +        return $this->categoryName;
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function getHtmlVariables()
 +    {
 +        ACLHandler::getInstance()->assignVariables($this->getObjectType()->objectTypeID);
 +
 +        $includeAclJavaScript = !static::$includedAclJavaScript;
 +        if (!static::$includedAclJavaScript) {
 +            static::$includedAclJavaScript = true;
 +        }
 +
 +        return [
 +            'includeAclJavaScript' => $includeAclJavaScript,
 +        ];
 +    }
 +
 +    /**
 +     * Returns the id of the edited object or `null` if no object is edited.
 +     *
 +     * @return  null|int
 +     */
 +    public function getObjectID()
 +    {
 +        return $this->objectID;
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function getObjectTypeDefinition()
 +    {
 +        return 'com.woltlab.wcf.acl';
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function hasSaveValue()
 +    {
 +        return false;
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function updatedObject(array $data, IStorableObject $object, $loadValues = true)
 +    {
 +        $this->objectID = $object->{$object::getDatabaseTableIndexName()};
 +
 +        if ($this->objectID === null) {
 +            throw new \UnexpectedValueException(
 +                "Cannot read object id from object of class '" . \get_class($object) . "'."
 +            );
 +        }
 +
 +        return $this;
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function populate()
 +    {
 +        parent::populate();
 +
 +        $this->getDocument()->getDataHandler()->addProcessor(new CustomFormDataProcessor(
 +            'acl',
 +            function (IFormDocument $document, array $parameters) {
 +                $parameters[$this->getObjectProperty() . '_aclObjectTypeID'] = $this->getObjectType()->objectTypeID;
 +
 +                return $parameters;
 +            }
 +        ));
 +
 +        return $this;
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function readValue()
 +    {
-         $valueSource = $_POST;
++        $valueSource = $_POST[$this->getPrefixedId()] ?? [];
 +        if ($this->getDocument()->isAjax()) {
 +            $valueSource = [];
 +            if (
 +                $this->getDocument()->hasRequestData($this->getPrefixedId())
 +                && \is_array($this->getDocument()->getRequestData($this->getPrefixedId()))
 +            ) {
 +                $valueSource = $this->getDocument()->getRequestData($this->getPrefixedId());
 +            }
 +        }
 +
 +        ACLHandler::getInstance()->readValues($this->getObjectType()->objectTypeID, $valueSource);
 +
 +        return $this;
 +    }
  }