-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathOptionForm.class.php
More file actions
150 lines (126 loc) · 3.84 KB
/
OptionForm.class.php
File metadata and controls
150 lines (126 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace wcf\acp\form;
use wcf\data\option\category\OptionCategory;
use wcf\data\option\OptionAction;
use wcf\event\acp\option\RewriteApplicationCollecting;
use wcf\system\application\ApplicationHandler;
use wcf\system\event\EventHandler;
use wcf\system\exception\IllegalLinkException;
use wcf\system\menu\acp\ACPMenu;
use wcf\system\option\OptionHandler;
use wcf\system\service\worker\ServiceWorkerHandler;
use wcf\system\style\StyleHandler;
use wcf\system\WCF;
/**
* Shows the option edit form.
*
* @author Marcel Werk
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*
* @extends AbstractOptionListForm<OptionHandler>
*/
class OptionForm extends AbstractOptionListForm
{
/**
* category option
* @var OptionCategory
*/
public $category;
/**
* category id
* @var int
*/
public $categoryID = 0;
/**
* the option tree
* @var mixed[]
*/
public $optionTree = [];
/**
* @inheritDoc
*/
protected $languageItemPattern = 'wcf.acp.option.option\d+';
/**
* @inheritDoc
*/
public function readParameters()
{
if (isset($_REQUEST['id'])) {
$this->categoryID = \intval($_REQUEST['id']);
}
$this->category = new OptionCategory($this->categoryID);
if (!$this->category->categoryID) {
throw new IllegalLinkException();
}
$this->categoryName = $this->category->categoryName;
parent::readParameters();
}
/**
* @inheritDoc
*/
public function save()
{
parent::save();
// save options
$saveOptions = $this->optionHandler->save('wcf.acp.option', 'wcf.acp.option.option');
$this->objectAction = new OptionAction([], 'updateAll', ['data' => $saveOptions]);
$this->objectAction->executeAction();
$this->saved();
ServiceWorkerHandler::getInstance()->updateKeys();
// reset styles to make sure the updated option values are used
StyleHandler::resetStylesheets();
// show success message
WCF::getTPL()->assign('success', true);
}
/**
* @inheritDoc
*/
public function readData()
{
parent::readData();
// load option tree
$this->optionTree = $this->optionHandler->getOptionTree($this->category->categoryName);
if (empty($_POST)) {
// not a valid top (level 1 or 2) category
if (!isset($this->optionTree[0])) {
throw new IllegalLinkException();
}
}
}
/**
* @inheritDoc
*/
public function assignVariables()
{
parent::assignVariables();
$event = new RewriteApplicationCollecting();
foreach (ApplicationHandler::getInstance()->getApplications() as $application) {
$event->register($application->getPackage()->getName(), WCF::getPath($application->getAbbreviation()));
}
EventHandler::getInstance()->fire($event);
$applications = $event->getApplications();
// Generate a static route to enforce URL rewriting.
$applications = \array_map(
static fn(string $path) => $path . 'core-rewrite-test/',
$applications
);
WCF::getTPL()->assign([
'category' => $this->category,
'optionTree' => $this->optionTree,
'rewriteTestApplications' => $applications,
]);
}
/**
* @inheritDoc
*/
public function show()
{
// set active menu item
ACPMenu::getInstance()->setActiveMenuItem('wcf.acp.option.category.' . $this->category->categoryName);
// check permission
WCF::getSession()->checkPermissions(['admin.configuration.canEditOption']);
// show form
parent::show();
}
}