'identifier' => 'com.woltlab.wcf.genericBox'.$boxEditor->boxID
]);
- if ($this->boxController && $this->boxController->getProcessor() instanceof IConditionBoxController) {
- $this->boxController->getProcessor()->setBox($box, false);
- $this->boxController->getProcessor()->saveConditions();
+ if ($this->boxController) {
+ if ($this->boxController->getProcessor() instanceof IConditionBoxController) {
+ $this->boxController->getProcessor()->setBox($box, false);
+ }
+ else {
+ $this->boxController->getProcessor()->setBox($box);
+ }
+
+ $this->boxController->getProcessor()->saveAdditionalData();
}
// save acl
use wcf\form\AbstractForm;
use wcf\system\acl\simple\SimpleAclHandler;
use wcf\system\box\IConditionBoxController;
+use wcf\system\condition\ConditionHandler;
use wcf\system\exception\IllegalLinkException;
use wcf\system\language\LanguageFactory;
use wcf\system\WCF;
$this->objectAction = new BoxAction([$this->box], 'update', ['data' => array_merge($this->additionalFields, $data), 'content' => $content, 'pageIDs' => $this->pageIDs]);
$this->objectAction->executeAction();
- if ($this->boxController && $this->boxController->getProcessor() instanceof IConditionBoxController) {
- $this->boxController->getProcessor()->setBox($this->box, false);
- $this->boxController->getProcessor()->saveConditions();
+ // delete old conditions
+ if ($this->box->getController() && $this->box->getController() instanceof IConditionBoxController && $this->box->getController()->getConditionDefinition() && (!$this->boxController || (!($this->boxController->getProcessor() instanceof IConditionBoxController)) || !$this->boxController->getProcessor()->getConditionDefinition())) {
+ ConditionHandler::getInstance()->deleteConditions($this->box->getController()->getConditionDefinition(), [$this->box->boxID]);
+ }
+
+ if ($this->boxController) {
+ // pass updated box to box controller as in `BoxAddForm::save()`
+ $box = new Box($this->box->boxID);
+ if ($this->boxController->getProcessor() instanceof IConditionBoxController) {
+ $this->boxController->getProcessor()->setBox($box, false);
+ }
+ else {
+ $this->boxController->getProcessor()->setBox($box);
+ }
+
+ $this->boxController->getProcessor()->saveAdditionalData();
}
SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.box', $this->box->boxID, $this->aclValues);
<?php
namespace wcf\system\box;
use wcf\data\box\Box;
+use wcf\data\box\BoxAction;
+use wcf\data\condition\Condition;
+use wcf\system\condition\ConditionHandler;
use wcf\system\event\EventHandler;
/**
$this->box = $box;
}
+ /**
+ * @inheritDoc
+ */
+ public function saveAdditionalData() {
+ // always write additional data to make sure that the additional data of the previous box controller
+ // are properly overwritten
+ (new BoxAction([$this->box], 'update', [
+ 'data' => ['additionalData' => serialize($this->getAdditionalData())]
+ ]))->executeAction();
+ }
+
+ /**
+ * Returns the additional data of the box.
+ *
+ * @return array
+ */
+ protected function getAdditionalData() {
+ return [];
+ }
+
/**
* @inheritDoc
*/
<?php
namespace wcf\system\box;
use wcf\data\box\Box;
-use wcf\data\box\BoxAction;
+use wcf\data\condition\ConditionAction;
use wcf\data\object\type\ObjectType;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\DatabaseObjectList;
}
/**
- * Returns the additional data saved with the box..
- *
- * @return array
+ * @inheritDoc
*/
protected function getAdditionalData() {
return [
protected function loadContent() {
$this->objectList = $this->getObjectList();
- if ($this->box->limit) {
+ if ($this->limit) {
$this->objectList->sqlLimit = $this->box->limit;
}
- if ($this->box->sortOrder && $this->box->sortField) {
+ if ($this->sortOrder && $this->sortField) {
$alias = $this->objectList->getDatabaseTableAlias();
- $this->objectList->sqlOrderBy = $this->box->sortField . ' ' . $this->box->sortOrder . ", " . ($alias ? $alias . "." : "") . $this->objectList->getDatabaseTableIndexName() . " " . $this->box->sortOrder;
+ $this->objectList->sqlOrderBy = $this->sortField . ' ' . $this->sortOrder . ", " . ($alias ? $alias . "." : "") . $this->objectList->getDatabaseTableIndexName() . " " . $this->sortOrder;
}
if ($this->conditionDefinition) {
/**
* @inheritDoc
*/
- public function saveConditions() {
- if (($this->sortField && $this->sortOrder) || $this->limit) {
- (new BoxAction([$this->box], 'update', [
- 'data' => [
- 'additionalData' => serialize(array_merge($this->box->additionalData, $this->getAdditionalData()))
- ]
- ]))->executeAction();
- }
+ public function saveAdditionalData() {
+ parent::saveAdditionalData();
if ($this->conditionDefinition) {
// do not use Box::getConditions() here to avoid setting box data by internally calling
// Box::getController()
- ConditionHandler::getInstance()->updateConditions($this->box->boxID, ConditionHandler::getInstance()->getConditions($this->conditionDefinition, $this->box->boxID), $this->conditionObjectTypes);
+ ConditionHandler::getInstance()->updateConditions(
+ $this->box->boxID,
+ ConditionHandler::getInstance()->getConditions($this->conditionDefinition, $this->box->boxID),
+ $this->conditionObjectTypes
+ );
}
}
parent::setBox($box);
if ($setConditionData) {
- $this->limit = $this->box->limit;
- $this->sortOrder = $this->box->sortOrder;
- $this->sortField = $this->box->sortField;
+ if ($this->defaultLimit !== null) {
+ $this->limit = $this->box->limit;
+ }
+
+ if (!empty($this->validSortFields)) {
+ $this->sortOrder = $this->box->sortOrder;
+ $this->sortField = $this->box->sortField;
+ }
if ($this->conditionDefinition) {
$conditions = [];
*/
public function setBox(Box $box);
+ /**
+ * Saves additional box data for box set via `setBox()`.
+ */
+ public function saveAdditionalData();
+
/**
* Returns a list of supported box positions.
*
*/
public function readConditions();
- /**
- * Saves the conditions for the box.
- */
- public function saveConditions();
-
/**
* Validates the read conditions for the box.
*/