Merge branch '5.3' into 5.4
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 21 Sep 2021 14:58:07 +0000 (16:58 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 21 Sep 2021 14:58:07 +0000 (16:58 +0200)
1  2 
wcfsetup/install/files/lib/system/option/AbstractCategoryMultiSelectOptionType.class.php

index 174946debe3801e13eb81f256e8c33398053208b,75e913345608c3a579de134c8ee9f20f7aedcc3e..b112108a4b0ec05f952786a2820498acfb46d092
@@@ -11,75 -9,60 +11,74 @@@ use wcf\util\ArrayUtil
  
  /**
   * Option type implementation for multi select lists.
 - * 
 - * @author    Marcel Werk
 - * @copyright 2001-2019 WoltLab GmbH
 - * @license   GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 - * @package   WoltLabSuite\Core\System\Option
 + *
 + * @author  Marcel Werk
 + * @copyright   2001-2019 WoltLab GmbH
 + * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 + * @package WoltLabSuite\Core\System\Option
   */
 -abstract class AbstractCategoryMultiSelectOptionType extends AbstractOptionType {
 -      /**
 -       * object type name
 -       * @var string
 -       */
 -      public $objectType = '';
 -      
 -      /**
 -       * node tree class
 -       * @var string
 -       */
 -      public $nodeTreeClassname = CategoryNodeTree::class;
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function getFormElement(Option $option, $value) {
 -              /** @var CategoryNodeTree $categoryTree */
 -              $categoryTree = new $this->nodeTreeClassname($this->objectType);
 -              $categoryList = $categoryTree->getIterator();
 -              
 -              WCF::getTPL()->assign([
 -                      'categoryList' => $categoryList,
 -                      'option' => $option,
 -                      'value' => !is_array($value) ? explode("\n", $value) : $value
 -              ]);
 -              return WCF::getTPL()->fetch('categoryMultiSelectOptionType');
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function validate(Option $option, $newValue) {
 -              if (!is_array($newValue)) $newValue = [];
 -              $newValue = ArrayUtil::toIntegerArray($newValue);
 -              
 -              foreach ($newValue as $categoryID) {
 -                      $category = CategoryHandler::getInstance()->getCategory($categoryID);
 -                      if ($category === null) throw new UserInputException($option->optionName, 'validationFailed');
 -                      if ($category->getObjectType()->objectType != $this->objectType) throw new UserInputException($option->optionName, 'validationFailed');
 -              }
 -      }
 -      
 -      /**
 -       * @inheritDoc
 -       */
 -      public function getData(Option $option, $newValue) {
 -              if (!is_array($newValue)) $newValue = [];
 -              return implode("\n", ArrayUtil::toIntegerArray($newValue));
 -      }
 +abstract class AbstractCategoryMultiSelectOptionType extends AbstractOptionType
 +{
 +    /**
 +     * object type name
 +     * @var string
 +     */
 +    public $objectType = '';
 +
 +    /**
 +     * node tree class
 +     * @var string
 +     */
 +    public $nodeTreeClassname = CategoryNodeTree::class;
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function getFormElement(Option $option, $value)
 +    {
 +        /** @var CategoryNodeTree $categoryTree */
 +        $categoryTree = new $this->nodeTreeClassname($this->objectType);
 +        $categoryList = $categoryTree->getIterator();
-         $categoryList->setMaxDepth(0);
 +
 +        WCF::getTPL()->assign([
 +            'categoryList' => $categoryList,
 +            'option' => $option,
 +            'value' => !\is_array($value) ? \explode("\n", $value) : $value,
 +        ]);
 +
 +        return WCF::getTPL()->fetch('categoryMultiSelectOptionType');
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function validate(Option $option, $newValue)
 +    {
 +        if (!\is_array($newValue)) {
 +            $newValue = [];
 +        }
 +        $newValue = ArrayUtil::toIntegerArray($newValue);
 +
 +        foreach ($newValue as $categoryID) {
 +            $category = CategoryHandler::getInstance()->getCategory($categoryID);
 +            if ($category === null) {
 +                throw new UserInputException($option->optionName, 'validationFailed');
 +            }
 +            if ($category->getObjectType()->objectType != $this->objectType) {
 +                throw new UserInputException($option->optionName, 'validationFailed');
 +            }
 +        }
 +    }
 +
 +    /**
 +     * @inheritDoc
 +     */
 +    public function getData(Option $option, $newValue)
 +    {
 +        if (!\is_array($newValue)) {
 +            $newValue = [];
 +        }
 +
 +        return \implode("\n", ArrayUtil::toIntegerArray($newValue));
 +    }
  }