mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Making a ContentItem's menu items URL resolved and not editable
--HG-- branch : dev
This commit is contained in:
@@ -60,12 +60,14 @@ namespace Orchard.Core.Navigation.Controllers {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
private static MenuItemEntry CreateMenuItemEntries(MenuPart menuPart) {
|
||||
private MenuItemEntry CreateMenuItemEntries(MenuPart menuPart) {
|
||||
return new MenuItemEntry {
|
||||
MenuItem = new UI.Navigation.MenuItem {
|
||||
Text = menuPart.MenuText,
|
||||
Position = menuPart.MenuPosition,
|
||||
Url = menuPart.Is<MenuItem>() ? menuPart.As<MenuItem>().Url : "menu part url"
|
||||
Url = menuPart.Is<MenuItem>()
|
||||
? menuPart.As<MenuItem>().Url
|
||||
: _navigationManager.GetUrl(null, _services.ContentManager.GetItemMetadata(menuPart).DisplayRouteValues)
|
||||
},
|
||||
MenuItemId = menuPart.Id,
|
||||
IsMenuItem = menuPart.Is<MenuItem>()
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Core.Navigation.Records;
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Routing;
|
||||
|
||||
namespace Orchard.UI.Navigation {
|
||||
public interface INavigationManager : IDependency {
|
||||
IEnumerable<MenuItem> BuildMenu(string menuName);
|
||||
string GetUrl(string menuItemUrl, RouteValueDictionary routeValueDictionary);
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
@@ -26,30 +26,33 @@ namespace Orchard.UI.Navigation {
|
||||
|
||||
private IEnumerable<MenuItem> FinishMenu(IEnumerable<MenuItem> menuItems) {
|
||||
foreach (var menuItem in menuItems) {
|
||||
var url = string.IsNullOrEmpty(menuItem.Url) && (menuItem.RouteValues == null || menuItem.RouteValues.Count == 0)
|
||||
? null
|
||||
: !string.IsNullOrEmpty(menuItem.Url)
|
||||
? menuItem.Url
|
||||
: _urlHelper.RouteUrl(menuItem.RouteValues);
|
||||
|
||||
if (!string.IsNullOrEmpty(url) && _urlHelper.RequestContext.HttpContext != null &&
|
||||
!(url.StartsWith("http://") || url.StartsWith("https://") || url.StartsWith("/"))) {
|
||||
if (url.StartsWith("~/")) {
|
||||
url = url.Substring(2);
|
||||
}
|
||||
var appPath = _urlHelper.RequestContext.HttpContext.Request.ApplicationPath;
|
||||
if (appPath == "/")
|
||||
appPath = "";
|
||||
url = string.Format("{0}/{1}", appPath, url);
|
||||
}
|
||||
|
||||
menuItem.Href = url;
|
||||
menuItem.Href = GetUrl(menuItem.Url, menuItem.RouteValues);
|
||||
menuItem.Items = FinishMenu(menuItem.Items.ToArray());
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
public string GetUrl(string menuItemUrl, RouteValueDictionary routeValueDictionary) {
|
||||
var url = string.IsNullOrEmpty(menuItemUrl) && (routeValueDictionary == null || routeValueDictionary.Count == 0)
|
||||
? null
|
||||
: !string.IsNullOrEmpty(menuItemUrl)
|
||||
? menuItemUrl
|
||||
: _urlHelper.RouteUrl(routeValueDictionary);
|
||||
|
||||
if (!string.IsNullOrEmpty(url) && _urlHelper.RequestContext.HttpContext != null &&
|
||||
!(url.StartsWith("http://") || url.StartsWith("https://") || url.StartsWith("/"))) {
|
||||
if (url.StartsWith("~/")) {
|
||||
url = url.Substring(2);
|
||||
}
|
||||
var appPath = _urlHelper.RequestContext.HttpContext.Request.ApplicationPath;
|
||||
if (appPath == "/")
|
||||
appPath = "";
|
||||
url = string.Format("{0}/{1}", appPath, url);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
private IEnumerable<MenuItem> Crop(IEnumerable<MenuItem> items) {
|
||||
foreach(var item in items) {
|
||||
if (item.Items.Any() || item.RouteValues != null)
|
||||
|
Reference in New Issue
Block a user