Improve order of box field validation
authorMatthias Schmidt <gravatronics@live.com>
Sat, 1 Oct 2016 12:08:09 +0000 (14:08 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 1 Oct 2016 12:38:09 +0000 (14:38 +0200)
Validate in order as fields appear in form and do not implicitly reset
the selected controller if name is invalid.

wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php

index fdd3280ac90f9957bc01029b6f88a682f9c3ca76..9df2a4279339b708c42059745ceb8ddca8b0ad2e 100644 (file)
@@ -281,6 +281,10 @@ class BoxAddForm extends AbstractForm {
                        
                        $this->readBoxImages();
                }
+               
+               if ($this->boxType === 'system') {
+                       $this->boxController = ObjectTypeCache::getInstance()->getObjectType($this->boxControllerID);
+               }
        }
        
        /**
@@ -312,7 +316,6 @@ class BoxAddForm extends AbstractForm {
                
                // validate controller
                if ($this->boxType === 'system') {
-                       $this->boxController = ObjectTypeCache::getInstance()->getObjectType($this->boxControllerID);
                        if ($this->boxController === null || $this->boxController->getDefinition()->definitionName != 'com.woltlab.wcf.boxController') {
                                throw new UserInputException('boxController');
                        }
@@ -365,16 +368,8 @@ class BoxAddForm extends AbstractForm {
                        $this->externalURL = '';
                }
                
-               // validate page ids
-               if (!empty($this->pageIDs)) {
-                       $conditionBuilder = new PreparedStatementConditionBuilder();
-                       $conditionBuilder->add('pageID IN (?)', [$this->pageIDs]);
-                       $sql = "SELECT  pageID
-                               FROM    wcf".WCF_N."_page
-                               " . $conditionBuilder;
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute($conditionBuilder->getParameters());
-                       $this->pageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
+               if ($this->boxController && $this->boxController->getProcessor() instanceof IConditionBoxController) {
+                       $this->boxController->getProcessor()->validateConditions();
                }
                
                // validate images
@@ -398,10 +393,6 @@ class BoxAddForm extends AbstractForm {
                        }
                }
                
-               if ($this->boxController && $this->boxController->getProcessor() instanceof IConditionBoxController) {
-                       $this->boxController->getProcessor()->validateConditions();
-               }
-               
                if ($this->boxType == 'text') {
                        if ($this->isMultilingual) {
                                foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
@@ -414,6 +405,18 @@ class BoxAddForm extends AbstractForm {
                                $this->htmlInputProcessors[0]->process((!empty($this->content[0]) ? $this->content[0] : ''), 'com.woltlab.wcf.box.content');
                        }
                }
+               
+               // validate page ids
+               if (!empty($this->pageIDs)) {
+                       $conditionBuilder = new PreparedStatementConditionBuilder();
+                       $conditionBuilder->add('pageID IN (?)', [$this->pageIDs]);
+                       $sql = "SELECT  pageID
+                               FROM    wcf".WCF_N."_page
+                               " . $conditionBuilder;
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute($conditionBuilder->getParameters());
+                       $this->pageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
+               }
        }
        
        /**