Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu item #1003

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.Menu.Models;
using System.Text.Json.Dynamic;
using YesSql;

namespace OrchardCore.Menu.Controllers
Expand Down Expand Up @@ -270,7 +271,7 @@ public async Task<IActionResult> Delete(string menuContentItemId, string menuIte
return NotFound();
}

var menuContentAsJson = (JsonObject)menu.Content;
var menuContentAsJson = (JsonDynamicObject)menu.Content;
// Look for the target menu item in the hierarchy.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not need , see :

public static implicit operator JsonObject(JsonDynamicObject value) => value._jsonObject;
public static implicit operator JsonDynamicObject(JsonObject value) => new(value);

var menuItem = FindMenuItem(menuContentAsJson, menuItemId);

Expand All @@ -280,8 +281,9 @@ public async Task<IActionResult> Delete(string menuContentItemId, string menuIte
return NotFound();
}

var menuItems = menuContentAsJson[nameof(MenuItemsListPart)]["MenuItems"] as JsonArray;
menuItems.Remove(menuItem);
var menuItemsListPart = menuContentAsJson[nameof(MenuItemsListPart)] as JsonDynamicObject;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the original code
We add Remove and other functions just to keep untransformed code like menu.Content.Remove working

var menuItems = menuItemsListPart?[nameof(MenuItemsListPart.MenuItems)] as JsonDynamicArray;
menuItems?.Remove(menuItem);

await _contentManager.SaveDraftAsync(menu);

Expand Down