mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Made the blog menu dynamic based off of how many blogs there are in the system for easier navigation
--HG-- branch : dev
This commit is contained in:
@@ -1,14 +1,42 @@
|
||||
using Orchard.UI.Navigation;
|
||||
using System.Linq;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Blogs {
|
||||
public class AdminMenu : INavigationProvider {
|
||||
private readonly IBlogService _blogService;
|
||||
|
||||
public AdminMenu(IBlogService blogService) {
|
||||
_blogService = blogService;
|
||||
}
|
||||
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.Add("Blogs", "2",
|
||||
menu => menu
|
||||
.Add("Manage Blogs", "1.0", item => item.Action("List", "BlogAdmin", new { area = "Orchard.Blogs" }).Permission(Permissions.MetaListBlogs))
|
||||
.Add("Add New Blog", "1.1", item => item.Action("Create", "BlogAdmin", new { area = "Orchard.Blogs" }).Permission(Permissions.ManageBlogs)));
|
||||
builder.Add("Blogs", "2", BuildMenu);
|
||||
}
|
||||
|
||||
private void BuildMenu(NavigationItemBuilder menu) {
|
||||
var blogs = _blogService.Get();
|
||||
var singleBlog = blogs.Count() == 1 ? blogs.ElementAt(0) : null;
|
||||
|
||||
if (singleBlog == null)
|
||||
menu.Add("Manage Blogs", "1.0",
|
||||
item =>
|
||||
item.Action("List", "BlogAdmin", new {area = "Orchard.Blogs"}).Permission(Permissions.MetaListBlogs));
|
||||
else
|
||||
menu.Add("Manage Blog", "1.0",
|
||||
item =>
|
||||
item.Action("Item", "BlogAdmin", new {area = "Orchard.Blogs", blogSlug = singleBlog.Slug}).Permission(Permissions.MetaListBlogs));
|
||||
|
||||
menu.Add("Add New Blog", "1.1",
|
||||
item =>
|
||||
item.Action("Create", "BlogAdmin", new {area = "Orchard.Blogs"}).Permission(Permissions.ManageBlogs));
|
||||
|
||||
if (singleBlog != null)
|
||||
menu.Add("Add New Post", "1.2",
|
||||
item =>
|
||||
item.Action("Create", "BlogPostAdmin", new {area = "Orchard.Blogs", blogSlug = singleBlog.Slug}).Permission(Permissions.PublishBlogPost));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user