Prevent the menu item itself being selected as its parent item
authorAlexander Ebert <ebert@woltlab.com>
Tue, 24 Aug 2021 21:23:55 +0000 (23:23 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 24 Aug 2021 21:23:55 +0000 (23:23 +0200)
See https://community.woltlab.com/thread/291999-men%C3%BCpunkt-verschwindet-wenn-%C3%BCbergeordneter-men%C3%BCpunkt-der-gleiche-ist/

wcfsetup/install/files/acp/templates/menuItemAdd.tpl
wcfsetup/install/files/lib/acp/form/MenuItemEditForm.class.php

index acf573429391b3f9abbe9d9d4eaea656a5689a7f..c99a7396d99928ce913726f1238986434726983c 100644 (file)
                                        <option value="0">{lang}wcf.global.noSelection{/lang}</option>
                                        
                                        {foreach from=$menuItemNodeList item=menuItemNode}
-                                               <option value="{@$menuItemNode->itemID}"{if $menuItemNode->itemID == $parentItemID} selected{/if}>{if $menuItemNode->getDepth() > 1}{@"&nbsp;&nbsp;&nbsp;&nbsp;"|str_repeat:($menuItemNode->getDepth() - 1)}{/if}{$menuItemNode->getTitle()}</option>
+                                               <option
+                                                       value="{@$menuItemNode->itemID}"
+                                                       {if $menuItemNode->itemID == $parentItemID} selected{/if}
+                                                       {if $menuItemNode->itemID == $itemID} disabled{/if}
+                                               >
+                                                       {if $menuItemNode->getDepth() > 1}{@"&nbsp;&nbsp;&nbsp;&nbsp;"|str_repeat:($menuItemNode->getDepth() - 1)}{/if}{$menuItemNode->getTitle()}
+                                               </option>
                                        {/foreach}
                                </select>
                                {if $errorField == 'parentItemID'}
index 03b11f02c37c5d5a99d5604f7da32c570021624c..2cfc6fd1a1aac89b348d3790f4ad534617ef5f33 100644 (file)
@@ -8,6 +8,7 @@ use wcf\data\menu\Menu;
 use wcf\data\page\PageNodeTree;
 use wcf\form\AbstractForm;
 use wcf\system\exception\IllegalLinkException;
+use wcf\system\exception\UserInputException;
 use wcf\system\language\I18nHandler;
 use wcf\system\page\handler\ILookupPageHandler;
 use wcf\system\WCF;
@@ -69,6 +70,18 @@ class MenuItemEditForm extends MenuItemAddForm
         }
     }
 
+    /**
+     * @inheritDoc
+     */
+    public function validate()
+    {
+        parent::validate();
+
+        if ($this->parentItemID == $this->itemID) {
+            throw new UserInputException('parentItemID');
+        }
+    }
+
     /**
      * @inheritDoc
      */