From c9a579eb40e25a44ae04462759ae2d42f4bc468f Mon Sep 17 00:00:00 2001
From: Fabian Schmid <fabian@sr.solutions>
Date: Tue, 3 Oct 2023 08:26:44 +0200
Subject: [PATCH] [FIX] 0037983: InvalidArgumentException with lost parent

---
 .../classes/Administration/class.ilMMSubitemFormGUI.php   | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/Services/MainMenu/classes/Administration/class.ilMMSubitemFormGUI.php b/Services/MainMenu/classes/Administration/class.ilMMSubitemFormGUI.php
index 7ea2d5971c7b..e863fcac5f03 100644
--- a/Services/MainMenu/classes/Administration/class.ilMMSubitemFormGUI.php
+++ b/Services/MainMenu/classes/Administration/class.ilMMSubitemFormGUI.php
@@ -130,11 +130,13 @@ private function initForm(): void
         // PARENT
         $parent = $f()->field()->select($txt('sub_parent'), $this->repository->getPossibleParentsForFormAndTable())
                       ->withRequired(true);
-        if (!$this->item_facade->isEmpty() && !$this->item_facade->isInLostItem()) {
+
+        $possible_parents = array_keys($this->repository->getPossibleParentsForFormAndTable());
+
+        if (!$this->item_facade->isEmpty() && !$this->item_facade->isInLostItem() && in_array($this->item_facade->getParentIdentificationString(), $possible_parents)) {
             $parent = $parent->withValue($this->item_facade->getParentIdentificationString());
         } else {
-            $array = array_keys($this->repository->getPossibleParentsForFormAndTable());
-            $parent = $parent->withValue(reset($array));
+            $parent = $parent->withValue(reset($possible_parents));
         }
         $items[self::F_PARENT] = $parent;