2 namespace wcf\acp\form
;
4 use wcf\data\box\BoxAction
;
5 use wcf\data\
object\type\ObjectTypeCache
;
6 use wcf\form\AbstractForm
;
7 use wcf\system\acl\simple\SimpleAclHandler
;
8 use wcf\system\box\IConditionBoxController
;
9 use wcf\system\condition\ConditionHandler
;
10 use wcf\system\exception\IllegalLinkException
;
11 use wcf\system\language\LanguageFactory
;
12 use wcf\system\version\VersionTracker
;
16 * Shows the box edit form.
19 * @copyright 2001-2017 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package WoltLabSuite\Core\Acp\Form
24 class BoxEditForm
extends BoxAddForm
{
28 public $activeMenuItem = 'wcf.acp.menu.link.cms.box.list';
45 public function readParameters() {
46 parent
::readParameters();
48 if (isset($_REQUEST['id'])) $this->boxID
= intval($_REQUEST['id']);
49 $this->box
= new Box($this->boxID
);
50 if (!$this->box
->boxID
) {
51 throw new IllegalLinkException();
53 if ($this->box
->boxType
== 'menu') {
54 // it's not allowed to edit menu boxes directly
55 throw new IllegalLinkException();
57 if ($this->box
->isMultilingual
) $this->isMultilingual
= 1;
63 protected function readBoxType() {
64 // not required for editing
70 protected function validateName() {
71 if (mb_strtolower($this->name
) != mb_strtolower($this->box
->name
)) {
72 parent
::validateName();
79 public function save() {
83 if ($this->boxType
== 'system' ||
$this->isMultilingual
) {
84 foreach (LanguageFactory
::getInstance()->getLanguages() as $language) {
85 $content[$language->languageID
] = [
86 'title' => !empty($this->title
[$language->languageID
]) ?
$this->title
[$language->languageID
] : '',
87 'content' => !empty($this->content
[$language->languageID
]) ?
$this->content
[$language->languageID
] : '',
88 'htmlInputProcessor' => isset($this->htmlInputProcessors
[$language->languageID
]) ?
$this->htmlInputProcessors
[$language->languageID
] : null,
89 'imageID' => !empty($this->imageID
[$language->languageID
]) ?
$this->imageID
[$language->languageID
] : null
95 'title' => !empty($this->title
[0]) ?
$this->title
[0] : '',
96 'content' => !empty($this->content
[0]) ?
$this->content
[0] : '',
97 'htmlInputProcessor' => isset($this->htmlInputProcessors
[0]) ?
$this->htmlInputProcessors
[0] : null,
98 'imageID' => !empty($this->imageID
[0]) ?
$this->imageID
[0] : null
103 'name' => $this->name
,
104 'isMultilingual' => $this->isMultilingual
,
105 'boxType' => $this->boxType
,
106 'position' => $this->position
,
107 'showOrder' => $this->showOrder
,
108 'visibleEverywhere' => $this->visibleEverywhere
,
109 'cssClassName' => $this->cssClassName
,
110 'showHeader' => $this->showHeader
,
111 'linkPageID' => $this->linkPageID
,
112 'linkPageObjectID' => $this->linkPageObjectID ?
: 0,
113 'externalURL' => $this->externalURL
115 if ($this->boxControllerID
) {
116 $data['objectTypeID'] = $this->boxControllerID
;
119 $this->objectAction
= new BoxAction([$this->box
], 'update', ['data' => array_merge($this->additionalFields
, $data), 'content' => $content, 'pageIDs' => $this->pageIDs
]);
120 $this->objectAction
->executeAction();
122 // delete old conditions
123 if ($this->box
->objectTypeID
) {
124 $className = ObjectTypeCache
::getInstance()->getObjectType($this->box
->objectTypeID
)->className
;
126 /** @var IConditionBoxController $oldController */
127 $oldController = new $className;
129 /** @noinspection PhpUndefinedMethodInspection */
130 if ($oldController instanceof IConditionBoxController
&& $oldController->getConditionDefinition() && (!$this->boxController ||
(!($this->boxController
->getProcessor() instanceof IConditionBoxController
)) ||
!$this->boxController
->getProcessor()->getConditionDefinition())) {
131 ConditionHandler
::getInstance()->deleteConditions($oldController->getConditionDefinition(), [$this->box
->boxID
]);
135 if ($this->boxController
) {
136 // pass updated box to box controller as in `BoxAddForm::save()`
137 $box = new Box($this->box
->boxID
);
138 if ($this->boxController
->getProcessor() instanceof IConditionBoxController
) {
139 $this->boxController
->getProcessor()->setBox($box, false);
142 $this->boxController
->getProcessor()->setBox($box);
145 $this->boxController
->getProcessor()->saveAdditionalData();
148 SimpleAclHandler
::getInstance()->setValues('com.woltlab.wcf.box', $this->box
->boxID
, $this->aclValues
);
153 // show success message
154 WCF
::getTPL()->assign('success', true);
160 public function readData() {
161 if (!empty($_POST) && !WCF
::getSession()->getPermission('admin.content.cms.canUseMedia')) {
162 foreach ($this->box
->getBoxContents() as $languageID => $content) {
163 $this->imageID
[$languageID] = $content->imageID
;
166 $this->readBoxImages();
172 $this->name
= $this->box
->name
;
173 $this->boxType
= $this->box
->boxType
;
174 $this->position
= $this->box
->position
;
175 $this->showOrder
= $this->box
->showOrder
;
176 $this->cssClassName
= $this->box
->cssClassName
;
177 $this->boxControllerID
= $this->box
->objectTypeID
;
178 if ($this->box
->showHeader
) $this->showHeader
= 1;
179 else $this->showHeader
= 0;
180 if ($this->box
->visibleEverywhere
) $this->visibleEverywhere
= 1;
181 else $this->visibleEverywhere
= 0;
182 $this->pageIDs
= $this->box
->getPageIDs();
183 $this->linkPageID
= $this->box
->linkPageID
;
184 $this->linkPageObjectID
= $this->box
->linkPageObjectID
;
185 $this->externalURL
= $this->box
->externalURL
;
186 if ($this->linkPageID
) $this->linkType
= 'internal';
187 if ($this->externalURL
) $this->linkType
= 'external';
189 foreach ($this->box
->getBoxContents() as $languageID => $content) {
190 $this->title
[$languageID] = $content->title
;
191 $this->content
[$languageID] = $content->content
;
192 $this->imageID
[$languageID] = $content->imageID
;
195 if ($this->boxControllerID
) {
196 $this->boxController
= ObjectTypeCache
::getInstance()->getObjectType($this->boxControllerID
);
197 if ($this->boxController
->getProcessor() instanceof IConditionBoxController
) {
198 $this->boxController
->getProcessor()->setBox($this->box
);
202 $this->aclValues
= SimpleAclHandler
::getInstance()->getValues('com.woltlab.wcf.box', $this->box
->boxID
);
204 $this->readBoxImages();
211 public function assignVariables() {
212 parent
::assignVariables();
214 WCF
::getTPL()->assign([
216 'boxID' => $this->boxID
,
218 'lastVersion' => VersionTracker
::getInstance()->getLastVersion('com.woltlab.wcf.box', $this->boxID
)