<dd>
<select name="boxControllerID" id="boxControllerID">
{foreach from=$availableBoxControllers item=availableBoxController}
- <option value="{@$availableBoxController->objectTypeID}"{if $boxController && $availableBoxController->objectTypeID == $boxController->objectTypeID} selected{/if}>{lang}wcf.acp.box.boxController.{@$availableBoxController->objectType}{/lang}</option>
+ <option value="{@$availableBoxController->objectTypeID}"{if $boxController && $availableBoxController->objectTypeID == $boxController->objectTypeID} selected{/if} data-supported-positions='[{implode from=$availableBoxPositions[$availableBoxController->objectTypeID] item=$__position}"{$__position}"{/implode}]'>{lang}wcf.acp.box.boxController.{@$availableBoxController->objectType}{/lang}</option>
{/foreach}
</select>
"use strict";
var _activePageId = 0;
+ var _boxController;
var _cache;
var _containerExternalLink;
var _containerPageID;
var _handlers;
var _pageId;
var _pageObjectId;
+ var _position;
/**
* @exports WoltLab/WCF/Acp/Ui/Box/Handler
init: function(handlers) {
_handlers = handlers;
+ _boxController = elById('boxControllerID');
+
_containerPageID = elById('linkPageIDContainer');
_containerExternalLink = elById('externalURLContainer');
_containerPageObjectId = elById('linkPageObjectIDContainer');
this._toggleLinkType(input.value);
}
}).bind(this));
+
+ if (_boxController !== null) {
+ _position = elById('position');
+ _boxController.addEventListener('change', this._setAvailableBoxPositions.bind(this));
+
+ // update positions on init
+ this._setAvailableBoxPositions();
+ }
},
/**
_pageObjectId.value = objectId;
_cache.set(_activePageId, objectId);
});
+ },
+
+ /**
+ * Updates the available box positions per box controller.
+ *
+ * @protected
+ */
+ _setAvailableBoxPositions: function() {
+ var supportedPositions = elData(_boxController.options[_boxController.selectedIndex], 'supported-positions');
+
+ var option;
+ for (var i = 0, length = _position.childElementCount; i < length; i++) {
+ option = _position.children[i];
+
+ option.disabled = (supportedPositions.indexOf(option.value) === -1);
+ }
}
};
});
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\language\LanguageFactory;
use wcf\system\page\handler\ILookupPageHandler;
+use wcf\system\page\handler\IMenuPageHandler;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
use wcf\util\ArrayUtil;
/**
* list of page handlers by page id
- * @var \wcf\system\page\handler\IMenuPageHandler[]
+ * @var IMenuPageHandler[]
*/
public $pageHandlers = [];
*/
public $htmlInputProcessors = [];
+ /**
+ * @var ObjectType[]
+ */
+ public $availableBoxControllers = [];
+
/**
* @inheritDoc
*/
}
}
}
+
+ $this->availableBoxControllers = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.boxController');
}
/**
'availableLanguages' => LanguageFactory::getInstance()->getLanguages(),
'availableBoxTypes' => Box::$availableBoxTypes,
'availablePositions' => Box::$availablePositions,
- 'availableBoxControllers' => ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.boxController'),
+ 'availableBoxControllers' => $this->availableBoxControllers,
'boxController' => $this->boxController,
'pageNodeList' => $this->pageNodeList,
'pageHandlers' => $this->pageHandlers,
use wcf\data\object\type\ObjectTypeCache;
use wcf\form\AbstractForm;
use wcf\system\acl\simple\SimpleAclHandler;
+use wcf\system\box\IBoxController;
use wcf\system\box\IConditionBoxController;
use wcf\system\exception\IllegalLinkException;
+use wcf\system\exception\UserInputException;
use wcf\system\language\LanguageFactory;
use wcf\system\WCF;
*/
public $activeMenuItem = 'wcf.acp.menu.link.cms.box.list';
+ /**
+ * list of available positions per box handler
+ * @var array
+ */
+ public $availableBoxPositions = [];
+
/**
* box id
* @var integer
* box object
* @var Box
*/
- public $box = null;
+ public $box;
/**
* @inheritDoc
throw new IllegalLinkException();
}
if ($this->box->isMultilingual) $this->isMultilingual = 1;
+
+ $this->readBoxPositions();
+ }
+
+ /**
+ * Loads available box positions per box controller.
+ */
+ protected function readBoxPositions() {
+ foreach ($this->availableBoxControllers as $boxController) {
+ /** @var IBoxController $controller */
+ $controller = $boxController->getProcessor();
+ $this->availableBoxPositions[$boxController->objectTypeID] = $controller::getSupportedPositions();
+ }
}
/**
}
}
+ /**
+ * @inheritDoc
+ */
+ public function validate() {
+ parent::validate();
+
+ $this->validateBoxPosition();
+ }
+
+ /**
+ * Validates the selected box position.
+ */
+ protected function validateBoxPosition() {
+ if ($this->boxType == 'system') {
+ if (!in_array($this->position, $this->availableBoxPositions[$this->boxController->objectTypeID])) {
+ throw new UserInputException('position', 'invalid');
+ }
+ }
+ }
+
/**
* @inheritDoc
*/
WCF::getTPL()->assign([
'action' => 'edit',
+ 'availableBoxPositions' => $this->availableBoxPositions,
'boxID' => $this->boxID,
'box' => $this->box
]);
* supported box positions
* @var string[]
*/
- protected $supportedPositions = [];
+ protected static $supportedPositions = [];
/**
* Creates a new instance of AbstractBoxController.
/**
* @inheritDoc
*/
- public function getSupportedPositions() {
- if (!empty($this->supportedPositions)) {
- return $this->supportedPositions;
+ public static function getSupportedPositions() {
+ if (!empty(static::$supportedPositions)) {
+ return static::$supportedPositions;
}
return Box::$availablePositions;
/**
* @inheritDoc
*/
- protected $supportedPositions = ['footerBoxes', 'sidebarLeft', 'sidebarRight', 'contentTop', 'contentBottom', 'footer'];
+ protected static $supportedPositions = ['footerBoxes', 'sidebarLeft', 'sidebarRight', 'contentTop', 'contentBottom', 'footer'];
/**
* @inheritDoc
/**
* @inheritDoc
*/
- protected $supportedPositions = ['sidebarLeft', 'sidebarRight', 'contentTop', 'contentBottom', 'top', 'bottom', 'footerBoxes'];
+ protected static $supportedPositions = ['sidebarLeft', 'sidebarRight', 'contentTop', 'contentBottom', 'top', 'bottom', 'footerBoxes'];
/**
* @inheritDoc
/**
* @inheritDoc
*/
- protected $supportedPositions = ['sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['sidebarLeft', 'sidebarRight'];
/**
* @inheritDoc
*
* @return string[]
*/
- public function getSupportedPositions();
+ public static function getSupportedPositions();
}
/**
* @inheritDoc
*/
- protected $supportedPositions = ['contentTop', 'contentBottom'];
+ protected static $supportedPositions = ['contentTop', 'contentBottom'];
/**
* @inheritDoc
/**
* @inheritDoc
*/
- protected $supportedPositions = ['contentTop', 'contentBottom', 'sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['contentTop', 'contentBottom', 'sidebarLeft', 'sidebarRight'];
/**
* @inheritDoc
/**
* @inheritDoc
*/
- protected $supportedPositions = ['contentTop', 'contentBottom', 'sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['contentTop', 'contentBottom', 'sidebarLeft', 'sidebarRight'];
/**
* @inheritDoc
/**
* @inheritDoc
*/
- protected $supportedPositions = ['sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['sidebarLeft', 'sidebarRight'];
/**
* @inheritDoc
/**
* @inheritDoc
*/
- protected $supportedPositions = ['sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['sidebarLeft', 'sidebarRight'];
/**
* @inheritDoc
/**
* @inheritDoc
*/
- protected $supportedPositions = ['sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['sidebarLeft', 'sidebarRight'];
/**
* @inheritDoc
/**
* @inheritDoc
*/
- protected $supportedPositions = ['sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['sidebarLeft', 'sidebarRight'];
/**
* @inheritDoc
/**
* @inheritDoc
*/
- protected $supportedPositions = ['footerBoxes', 'sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['footerBoxes', 'sidebarLeft', 'sidebarRight'];
/**
* taggable object type
/**
* @inheritDoc
*/
- protected $supportedPositions = ['sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['sidebarLeft', 'sidebarRight'];
/**
* template name
/**
* @inheritDoc
*/
- protected $supportedPositions = ['footerBoxes', 'sidebarLeft', 'sidebarRight'];
+ protected static $supportedPositions = ['footerBoxes', 'sidebarLeft', 'sidebarRight'];
/**
* enables the display of the user online record
<item name="wcf.acp.box.list"><![CDATA[Boxen]]></item>
<item name="wcf.acp.box.name.error.notUnique"><![CDATA[Dieser Name wird bereits von einer anderen Box verwendet.]]></item>
<item name="wcf.acp.box.position"><![CDATA[Position]]></item>
+ <item name="wcf.acp.box.position.error.invalid"><![CDATA[Die ausgewählte Position ist ungültig.]]></item>
<item name="wcf.acp.box.showHeader"><![CDATA[Box-Titel anzeigen]]></item>
<item name="wcf.acp.box.type"><![CDATA[Box-Typ]]></item>
<item name="wcf.acp.box.type.html"><![CDATA[HTML]]></item>
<item name="wcf.acp.box.list"><![CDATA[Boxes]]></item>
<item name="wcf.acp.box.name.error.notUnique"><![CDATA[Name is already in use.]]></item>
<item name="wcf.acp.box.position"><![CDATA[Position]]></item>
+ <item name="wcf.acp.box.position.error.invalid"><![CDATA[The selected position is invalid.]]></item>
<item name="wcf.acp.box.showHeader"><![CDATA[Show box title]]></item>
<item name="wcf.acp.box.type"><![CDATA[Page Type]]></item>
<item name="wcf.acp.box.type.html"><![CDATA[HTML]]></item>