Make own menuItem unselectable when editing
authorCyperghost <olaf_schmitz_1@t-online.de>
Thu, 21 Nov 2024 08:43:15 +0000 (09:43 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Thu, 21 Nov 2024 08:43:15 +0000 (09:43 +0100)
wcfsetup/install/files/lib/acp/form/MenuItemAddForm.class.php

index 934dd61162c90097f7bc67149994587bde792d35..e3cc667d7c2eabe91814977271e40ebacc2805b6 100644 (file)
@@ -5,6 +5,7 @@ namespace wcf\acp\form;
 use wcf\data\IStorableObject;
 use wcf\data\menu\item\MenuItem;
 use wcf\data\menu\item\MenuItemAction;
+use wcf\data\menu\item\MenuItemNode;
 use wcf\data\menu\item\MenuItemNodeTree;
 use wcf\data\menu\Menu;
 use wcf\data\page\Page;
@@ -108,7 +109,20 @@ class MenuItemAddForm extends AbstractFormBuilderForm
                 ->appendChildren([
                     SelectFormField::create('parentItemID')
                         ->label('wcf.acp.menu.item.parentItem')
-                        ->options($this->menuItemNodeList, true),
+                        ->options(function () {
+                            $result = [];
+                            foreach ($this->menuItemNodeList as $menuItem) {
+                                \assert($menuItem instanceof MenuItemNode);
+
+                                $result[] = [
+                                    'depth' => $menuItem->getDepth(),
+                                    'isSelectable' => $menuItem->itemID !== $this->formObject?->itemID,
+                                    'label' => $menuItem->getTitle(),
+                                    'value' => $menuItem->getObjectID(),
+                                ];
+                            }
+                            return $result;
+                        }, true),
                     TitleFormField::create()
                         ->i18n()
                         ->required()