mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
Adding ContentItemMetadata route values for widgets, blogs and blog posts
- also removing the default (Core.Contents specific) metadata from Orchard.ContentManagement.ContentItemMetadata work items: 16683, 16791 --HG-- branch : dev
This commit is contained in:
@@ -166,7 +166,7 @@ namespace Orchard.Core.Tests.Feeds.Controllers {
|
||||
|
||||
var mockContentManager = new Mock<IContentManager>();
|
||||
mockContentManager.Setup(x => x.GetItemMetadata(It.IsAny<IContent>()))
|
||||
.Returns(new ContentItemMetadata(hello) { DisplayText = "foo" });
|
||||
.Returns(new ContentItemMetadata() { DisplayText = "foo" });
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
//builder.RegisterModule(new ImplicitCollectionSupportModule());
|
||||
|
@@ -31,7 +31,8 @@ namespace Orchard.Core.Contents.Handlers {
|
||||
context.Metadata.RemoveRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Contents"},
|
||||
{"Controller", "Item"},
|
||||
{"Action", "Remove"}
|
||||
{"Action", "Remove"},
|
||||
{"Id", context.ContentItem.Id}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
|
||||
@@ -14,5 +16,30 @@ namespace Orchard.Blogs.Handlers {
|
||||
context.Shape.PostCount = blog.PostCount;
|
||||
});
|
||||
}
|
||||
|
||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||
var blog = context.ContentItem.As<BlogPart>();
|
||||
|
||||
if (blog == null)
|
||||
return;
|
||||
|
||||
context.Metadata.CreateRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "BlogAdmin"},
|
||||
{"Action", "Create"}
|
||||
};
|
||||
context.Metadata.EditorRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "BlogAdmin"},
|
||||
{"Action", "Edit"},
|
||||
{"Id", context.ContentItem.Id}
|
||||
};
|
||||
context.Metadata.RemoveRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "BlogAdmin"},
|
||||
{"Action", "Remove"},
|
||||
{"Id", context.ContentItem.Id}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -6,18 +6,15 @@ using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Core.Routable.Models;
|
||||
|
||||
namespace Orchard.Blogs.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class BlogPostPartHandler : ContentHandler {
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public BlogPostPartHandler(IBlogService blogService, IBlogPostService blogPostService, IOrchardServices orchardServices, RequestContext requestContext) {
|
||||
public BlogPostPartHandler(IBlogService blogService, IBlogPostService blogPostService, RequestContext requestContext) {
|
||||
_blogPostService = blogPostService;
|
||||
_orchardServices = orchardServices;
|
||||
T = NullLocalizer.Instance;
|
||||
|
||||
Action<BlogPart> updateBlogPostCount =
|
||||
(blog => {
|
||||
@@ -65,6 +62,32 @@ namespace Orchard.Blogs.Handlers {
|
||||
context.Shape.Blog = blogPost.BlogPart;
|
||||
}
|
||||
|
||||
Localizer T { get; set; }
|
||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||
var blogPost = context.ContentItem.As<BlogPostPart>();
|
||||
|
||||
if (blogPost == null)
|
||||
return;
|
||||
|
||||
context.Metadata.CreateRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "BlogPostAdmin"},
|
||||
{"Action", "Create"},
|
||||
{"blogSlug", blogPost.BlogPart.As<RoutePart>().Slug}
|
||||
};
|
||||
context.Metadata.EditorRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "BlogPostAdmin"},
|
||||
{"Action", "Edit"},
|
||||
{"postId", context.ContentItem.Id},
|
||||
{"blogSlug", blogPost.BlogPart.As<RoutePart>().Slug}
|
||||
};
|
||||
context.Metadata.RemoveRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "BlogPostAdmin"},
|
||||
{"Action", "Delete"},
|
||||
{"postId", context.ContentItem.Id},
|
||||
{"blogSlug", blogPost.BlogPart.As<RoutePart>().Slug}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
using JetBrains.Annotations;
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
using Orchard.Widgets.Models;
|
||||
@@ -9,5 +11,32 @@ namespace Orchard.Widgets.Handlers {
|
||||
public WidgetPartHandler(IRepository<WidgetPartRecord> widgetsRepository) {
|
||||
Filters.Add(StorageFilter.For(widgetsRepository));
|
||||
}
|
||||
|
||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||
var widget = context.ContentItem.As<WidgetPart>();
|
||||
|
||||
if (widget == null)
|
||||
return;
|
||||
|
||||
// create needs to go through the add widget flow (index -> [select layer -> ] add [widget type] to layer)
|
||||
context.Metadata.CreateRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Widgets"},
|
||||
{"Controller", "Admin"},
|
||||
{"Action", "Index"}
|
||||
};
|
||||
context.Metadata.EditorRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Widgets"},
|
||||
{"Controller", "Admin"},
|
||||
{"Action", "EditWidget"},
|
||||
{"Id", context.ContentItem.Id}
|
||||
};
|
||||
// remove goes through edit widget...
|
||||
context.Metadata.RemoveRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Widgets"},
|
||||
{"Controller", "Admin"},
|
||||
{"Action", "EditWidget"},
|
||||
{"Id", context.ContentItem.Id}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,56 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Routing;
|
||||
|
||||
namespace Orchard.ContentManagement {
|
||||
public class ContentItemMetadata {
|
||||
public ContentItemMetadata(IContent item) {
|
||||
DisplayRouteValues = GetDisplayRouteValues(item);
|
||||
EditorRouteValues = GetEditorRouteValues(item);
|
||||
CreateRouteValues = GetCreateRouteValues(item);
|
||||
}
|
||||
|
||||
public string DisplayText { get; set; }
|
||||
public RouteValueDictionary DisplayRouteValues { get; set; }
|
||||
public RouteValueDictionary EditorRouteValues { get; set; }
|
||||
public RouteValueDictionary CreateRouteValues { get; set; }
|
||||
public RouteValueDictionary RemoveRouteValues { get; set; }
|
||||
|
||||
public IEnumerable<string> DisplayGroups { get; set; }
|
||||
public IEnumerable<string> EditorGroups { get; set; }
|
||||
|
||||
private static RouteValueDictionary GetDisplayRouteValues(IContent item) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Contents"},
|
||||
{"Controller", "Item"},
|
||||
{"Action", "Display"},
|
||||
{"id", item.ContentItem.Id}
|
||||
};
|
||||
}
|
||||
|
||||
private static RouteValueDictionary GetEditorRouteValues(IContent item) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Contents"},
|
||||
{"Controller", "Admin"},
|
||||
{"Action", "Edit"},
|
||||
{"id", item.ContentItem.Id}
|
||||
};
|
||||
}
|
||||
|
||||
private static RouteValueDictionary GetCreateRouteValues(IContent item) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Contents"},
|
||||
{"Controller", "Admin"},
|
||||
{"Action", "Create"},
|
||||
{"id", item.ContentItem.ContentType}
|
||||
};
|
||||
}
|
||||
|
||||
private static RouteValueDictionary GetRemoveRouteValues(IContent item) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Contents"},
|
||||
{"Controller", "Admin"},
|
||||
{"Action", "Remove"}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -350,20 +350,10 @@ namespace Orchard.ContentManagement {
|
||||
public ContentItemMetadata GetItemMetadata(IContent content) {
|
||||
var context = new GetContentItemMetadataContext {
|
||||
ContentItem = content.ContentItem,
|
||||
Metadata = new ContentItemMetadata(content)
|
||||
Metadata = new ContentItemMetadata()
|
||||
};
|
||||
|
||||
Handlers.Invoke(handler => handler.GetContentItemMetadata(context), Logger);
|
||||
//-- was - from ContentItemDriver --
|
||||
//void IContentItemDriver.GetContentItemMetadata(GetContentItemMetadataContext context) {
|
||||
// var item = context.ContentItem.As<TContent>();
|
||||
// if (item != null) {
|
||||
// context.Metadata.DisplayText = GetDisplayText(item) ?? context.Metadata.DisplayText;
|
||||
// context.Metadata.DisplayRouteValues = GetDisplayRouteValues(item) ?? context.Metadata.DisplayRouteValues;
|
||||
// context.Metadata.EditorRouteValues = GetEditorRouteValues(item) ?? context.Metadata.EditorRouteValues;
|
||||
// context.Metadata.CreateRouteValues = GetCreateRouteValues(item) ?? context.Metadata.CreateRouteValues;
|
||||
// }
|
||||
//}
|
||||
|
||||
return context.Metadata;
|
||||
}
|
||||
|
Reference in New Issue
Block a user