From: Tim Düsterhus Date: Tue, 21 Sep 2021 14:58:07 +0000 (+0200) Subject: Merge branch '5.3' into 5.4 X-Git-Tag: 5.4.8_dev_1~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c31e5cc54d95bd677410f7574f2a86fe4fe4dc61;p=GitHub%2FWoltLab%2FWCF.git Merge branch '5.3' into 5.4 --- c31e5cc54d95bd677410f7574f2a86fe4fe4dc61 diff --cc wcfsetup/install/files/lib/system/option/AbstractCategoryMultiSelectOptionType.class.php index 174946debe,75e9133456..b112108a4b --- a/wcfsetup/install/files/lib/system/option/AbstractCategoryMultiSelectOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/AbstractCategoryMultiSelectOptionType.class.php @@@ -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 - * @package WoltLabSuite\Core\System\Option + * + * @author Marcel Werk + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @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)); + } }