Fixed issue in validation of box position
authorMarcel Werk <burntime@woltlab.com>
Tue, 12 Jul 2016 09:21:35 +0000 (11:21 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 12 Jul 2016 09:21:35 +0000 (11:21 +0200)
wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php
wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php

index b388b7180f094e2aa30eadb775188b4bcdf54f7d..eacb9df4f1d94eb612fecd49a16155abff6d6747 100644 (file)
@@ -11,6 +11,7 @@ use wcf\data\page\Page;
 use wcf\data\page\PageNodeTree;
 use wcf\form\AbstractForm;
 use wcf\system\acl\simple\SimpleAclHandler;
+use wcf\system\box\IBoxController;
 use wcf\system\box\IConditionBoxController;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\IllegalLinkException;
@@ -187,6 +188,12 @@ class BoxAddForm extends AbstractForm {
         */
        public $availableBoxControllers = [];
        
+       /**
+        * list of available positions per box handler
+        * @var array
+        */
+       public $availableBoxPositions = [];
+       
        /**
         * @inheritDoc
         */
@@ -208,6 +215,18 @@ class BoxAddForm extends AbstractForm {
                }
                
                $this->availableBoxControllers = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.boxController');
+               $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();
+               }
        }
        
        /**
@@ -307,9 +326,7 @@ class BoxAddForm extends AbstractForm {
                }
                
                // validate box position
-               if (!in_array($this->position, Box::$availablePositions)) {
-                       throw new UserInputException('position');
-               }
+               $this->validateBoxPosition();
                
                // validate link
                if ($this->linkType == 'internal') {
@@ -399,6 +416,21 @@ class BoxAddForm extends AbstractForm {
                }
        }
        
+       /**
+        * Validates the selected box position.
+        */
+       protected function validateBoxPosition() {
+               if (!in_array($this->position, Box::$availablePositions)) {
+                       throw new UserInputException('position');
+               }
+               
+               if ($this->boxType == 'system') {
+                       if (!in_array($this->position, $this->availableBoxPositions[$this->boxController->objectTypeID])) {
+                               throw new UserInputException('position', 'invalid');
+                       }
+               }
+       }
+       
        /**
         * @inheritDoc
         */
@@ -507,7 +539,8 @@ class BoxAddForm extends AbstractForm {
                        'boxController' => $this->boxController,
                        'pageNodeList' => $this->pageNodeList,
                        'pageHandlers' => $this->pageHandlers,
-                       'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues)
+                       'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues),
+                       'availableBoxPositions' => $this->availableBoxPositions
                ]);
        }
 }
index e95643eba7a9e4dd48f185e671c6cd630815f759..45a861a29f476de4a1358ffb434ab3dd2a3427e7 100644 (file)
@@ -27,12 +27,6 @@ class BoxEditForm extends BoxAddForm {
         */
        public $activeMenuItem = 'wcf.acp.menu.link.cms.box.list';
        
-       /**
-        * list of available positions per box handler
-        * @var array
-        */
-       public $availableBoxPositions = [];
-       
        /**
         * box id
         * @var integer
@@ -61,19 +55,6 @@ class BoxEditForm extends BoxAddForm {
                        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();
-               }
        }
        
        /**
@@ -98,19 +79,10 @@ class BoxEditForm extends BoxAddForm {
        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
@@ -231,7 +203,6 @@ class BoxEditForm extends BoxAddForm {
                
                WCF::getTPL()->assign([
                        'action' => 'edit',
-                       'availableBoxPositions' => $this->availableBoxPositions,
                        'boxID' => $this->boxID,
                        'box' => $this->box
                ]);