2 namespace wcf\acp\form
;
3 use wcf\data\user\option\category\UserOptionCategoryAction
;
4 use wcf\data\user\option\category\UserOptionCategoryEditor
;
5 use wcf\form\AbstractForm
;
6 use wcf\system\exception\UserInputException
;
7 use wcf\system\language\I18nHandler
;
8 use wcf\system\request\LinkHandler
;
12 * Shows the form for adding new user option categories.
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\Acp\Form
19 class UserOptionCategoryAddForm
extends AbstractForm
{
23 public $activeMenuItem = 'wcf.acp.menu.link.user.option.category.add';
28 public $neededPermissions = ['admin.user.canManageUserOption'];
34 public $categoryName = '';
40 public $showOrder = 0;
45 public function readParameters() {
46 parent
::readParameters();
48 I18nHandler
::getInstance()->register('categoryName');
54 public function readFormParameters() {
55 parent
::readFormParameters();
57 I18nHandler
::getInstance()->readValues();
59 if (I18nHandler
::getInstance()->isPlainValue('categoryName')) $this->categoryName
= I18nHandler
::getInstance()->getValue('categoryName');
60 if (isset($_POST['showOrder'])) $this->showOrder
= intval($_POST['showOrder']);
66 public function validate() {
69 if (!I18nHandler
::getInstance()->validateValue('categoryName', true)) {
70 throw new UserInputException('categoryName', 'multilingual');
77 public function save() {
81 $this->objectAction
= new UserOptionCategoryAction([], 'create', ['data' => array_merge($this->additionalFields
, [
82 'parentCategoryName' => 'profile',
83 'categoryName' => $this->categoryName
,
84 'showOrder' => $this->showOrder
86 $this->objectAction
->executeAction();
89 $returnValues = $this->objectAction
->getReturnValues();
90 $categoryID = $returnValues['returnValues']->categoryID
;
91 I18nHandler
::getInstance()->save('categoryName', 'wcf.user.option.category.category'.$categoryID, 'wcf.user.option');
92 $categoryEditor = new UserOptionCategoryEditor($returnValues['returnValues']);
93 $categoryEditor->update([
94 'categoryName' => 'category'.$categoryID
99 $this->categoryName
= '';
100 $this->showOrder
= 0;
102 I18nHandler
::getInstance()->reset();
104 // show success message
105 WCF
::getTPL()->assign([
107 'objectEditLink' => LinkHandler
::getInstance()->getControllerLink(UserOptionCategoryEditForm
::class, ['id' => $categoryID]),
114 public function assignVariables() {
115 parent
::assignVariables();
117 I18nHandler
::getInstance()->assignVariables();
119 WCF
::getTPL()->assign([
121 'categoryName' => $this->categoryName
,
122 'showOrder' => $this->showOrder