From f9bfc194c4d1c019ec820d36b6bc2946c499eb17 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Wed, 13 Mar 2024 18:47:20 +0300 Subject: [PATCH 1/3] Fix menu item deletion --- .../OrchardCore.Menu/Controllers/AdminController.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs index 5e2763c1d03..ff7a1b12595 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs @@ -270,8 +270,9 @@ public async Task Delete(string menuContentItemId, string menuIte return NotFound(); } + var menuContentAsJson = (JsonObject)menu.Content; // Look for the target menu item in the hierarchy. - var menuItem = FindMenuItem((JsonObject)menu.Content, menuItemId); + var menuItem = FindMenuItem(menuContentAsJson, menuItemId); // Couldn't find targeted menu item. if (menuItem == null) @@ -279,7 +280,8 @@ public async Task Delete(string menuContentItemId, string menuIte return NotFound(); } - menu.Content.Remove(menuItemId); + var menuItems = menuContentAsJson[nameof(MenuItemsListPart)]["MenuItems"] as JsonArray; + menuItems.Remove(menuItem); await _contentManager.SaveDraftAsync(menu); From 728554a244723f5cf8d2ed110ecd2578435eb358 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 14 Mar 2024 21:21:51 +0300 Subject: [PATCH 2/3] Update src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sára El-Saig --- .../OrchardCore.Menu/Controllers/AdminController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs index ff7a1b12595..0b3ced0f42e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs @@ -280,7 +280,7 @@ public async Task Delete(string menuContentItemId, string menuIte return NotFound(); } - var menuItems = menuContentAsJson[nameof(MenuItemsListPart)]["MenuItems"] as JsonArray; + var menuItems = menuContentAsJson[nameof(MenuItemsListPart)]?[nameof(MenuItemsListPart.MenuItems)] as JsonArray; menuItems.Remove(menuItem); await _contentManager.SaveDraftAsync(menu); From 45993eab1d8efef88a3567f0a82bcd992cd8faa9 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 14 Mar 2024 21:31:45 +0300 Subject: [PATCH 3/3] Address feedback --- .../OrchardCore.Menu/Controllers/AdminController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs index 0b3ced0f42e..6a4da99171e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs @@ -281,7 +281,7 @@ public async Task Delete(string menuContentItemId, string menuIte } var menuItems = menuContentAsJson[nameof(MenuItemsListPart)]?[nameof(MenuItemsListPart.MenuItems)] as JsonArray; - menuItems.Remove(menuItem); + menuItems?.Remove(menuItem); await _contentManager.SaveDraftAsync(menu);