From: Matthias Schmidt Date: Sun, 28 Jul 2019 13:17:59 +0000 (+0200) Subject: Append (instead of prepend) menu item during page creation X-Git-Tag: 5.2.0_Alpha_4~31 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=26ae9f271fe453215b804ca187cb280a403e744f;p=GitHub%2FWoltLab%2FWCF.git Append (instead of prepend) menu item during page creation See #2998 --- diff --git a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php index 63d4cc71f4..ce2b54da9d 100644 --- a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php @@ -17,6 +17,7 @@ use wcf\data\page\PageNodeTree; use wcf\data\smiley\SmileyCache; use wcf\form\AbstractForm; use wcf\system\acl\simple\SimpleAclHandler; +use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\UserInputException; use wcf\system\html\input\HtmlInputProcessor; @@ -589,12 +590,29 @@ class PageAddForm extends AbstractForm { // add page to main menu if ($this->addPageToMainMenu) { + // select maximum showOrder value so that new menu item will be appened + $conditionBuilder = new PreparedStatementConditionBuilder(); + if ($this->parentMenuItemID) { + $conditionBuilder->add('parentItemID = ?', [$this->parentMenuItemID]); + } + else { + $conditionBuilder->add('parentItemID IS NULL'); + } + + $sql = "SELECT MAX(showOrder) + FROM wcf" . WCF_N . "_menu_item + " . $conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + $maxShowOrder = $statement->fetchSingleColumn() ?? 0; + $menuItemAction = new MenuItemAction([], 'create', ['data' => [ 'isDisabled' => $this->isDisabled ? 1 : 0, 'title' => (!$this->isMultilingual ? $this->title[0] : ''), 'pageID' => $page->pageID, 'menuID' => MenuCache::getInstance()->getMainMenuID(), 'parentItemID' => $this->parentMenuItemID, + 'showOrder' => $maxShowOrder + 1, 'identifier' => StringUtil::getRandomID(), 'packageID' => 1 ]]);