mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 21:13:35 +08:00
Moving ContentType definitions into ItemDriver implementations
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044436
This commit is contained in:
@@ -11,15 +11,23 @@ using Orchard.ContentManagement.ViewModels;
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
[UsedImplicitly]
|
||||
public class BlogDriver : ItemDriver<Blog> {
|
||||
public readonly static ContentType ContentType = new ContentType {
|
||||
Name = "blog",
|
||||
DisplayName = "Blog"
|
||||
};
|
||||
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
|
||||
public BlogDriver(IContentManager contentManager, IBlogPostService blogPostService)
|
||||
: base(Blog.ContentType) {
|
||||
public BlogDriver(IContentManager contentManager, IBlogPostService blogPostService) {
|
||||
_contentManager = contentManager;
|
||||
_blogPostService = blogPostService;
|
||||
}
|
||||
|
||||
protected override ContentType GetContentType() {
|
||||
return ContentType;
|
||||
}
|
||||
|
||||
protected override string Prefix { get { return ""; } }
|
||||
|
||||
protected override string GetDisplayText(Blog item) {
|
||||
|
@@ -11,8 +11,13 @@ using Orchard.ContentManagement.Drivers;
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
[UsedImplicitly]
|
||||
public class BlogPostDriver : ItemDriver<BlogPost> {
|
||||
public BlogPostDriver()
|
||||
: base(BlogPost.ContentType) {
|
||||
public readonly static ContentType ContentType = new ContentType {
|
||||
Name = "blogpost",
|
||||
DisplayName = "Blog Post"
|
||||
};
|
||||
|
||||
protected override ContentType GetContentType() {
|
||||
return ContentType;
|
||||
}
|
||||
|
||||
protected override string Prefix { get { return ""; } }
|
||||
@@ -41,11 +46,15 @@ namespace Orchard.Blogs.Controllers {
|
||||
};
|
||||
}
|
||||
|
||||
protected override DriverResult Display(BlogPost post, string displayType) {
|
||||
return ItemTemplate("Items/Blogs.BlogPost").LongestMatch(displayType, "Summary", "SummaryAdmin");
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(BlogPost post) {
|
||||
return Combined(
|
||||
ItemTemplate("Items/Blogs.BlogPost"),
|
||||
PartTemplate(post, "Parts/Blogs.BlogPost.Fields").Location("primary", "1"),
|
||||
PartTemplate(post, "Parts/Blogs.BlogPost.Publish").Location("secondary", "1")
|
||||
);
|
||||
PartTemplate(post, "Parts/Blogs.BlogPost.Publish").Location("secondary", "1"));
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(BlogPost post, IUpdateModel updater) {
|
||||
|
@@ -4,7 +4,6 @@ using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class Blog : ContentPart<BlogRecord> {
|
||||
public readonly static ContentType ContentType = new ContentType { Name = "blog", DisplayName = "Blog" };
|
||||
|
||||
public int Id { get { return ContentItem.Id; } }
|
||||
|
||||
|
@@ -1,19 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Blogs.Controllers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
[UsedImplicitly]
|
||||
public class BlogHandler : ContentHandler {
|
||||
public override IEnumerable<ContentType> GetContentTypes() {
|
||||
return new[] { Blog.ContentType };
|
||||
}
|
||||
|
||||
public BlogHandler(IRepository<BlogRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<Blog>("blog"));
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>("blog"));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>("blog"));
|
||||
Filters.Add(new ActivatingFilter<Blog>(BlogDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>(BlogDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>(BlogDriver.ContentType.Name));
|
||||
Filters.Add(new StorageFilter<BlogRecord>(repository));
|
||||
}
|
||||
}
|
||||
|
@@ -7,8 +7,6 @@ using Orchard.Security;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class BlogPost : ContentPart<BlogPostRecord> {
|
||||
public readonly static ContentType ContentType = new ContentType { Name = "blogpost", DisplayName = "Blog Post" };
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id { get { return ContentItem.Id; } }
|
||||
|
||||
|
@@ -1,28 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Blogs.Services;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Blogs.Controllers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.ContentManagement.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
[UsedImplicitly]
|
||||
public class BlogPostHandler : ContentHandler {
|
||||
public override IEnumerable<ContentType> GetContentTypes() {
|
||||
return new[] { BlogPost.ContentType };
|
||||
}
|
||||
|
||||
public BlogPostHandler(
|
||||
IRepository<BlogPostRecord> repository,
|
||||
IContentManager contentManager,
|
||||
IBlogPostService blogPostService) {
|
||||
public BlogPostHandler(IRepository<BlogPostRecord> repository) {
|
||||
|
||||
Filters.Add(new ActivatingFilter<BlogPost>("blogpost"));
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>("blogpost"));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>("blogpost"));
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>("blogpost"));
|
||||
Filters.Add(new ActivatingFilter<BlogPost>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new StorageFilter<BlogPostRecord>(repository));
|
||||
|
||||
|
||||
|
@@ -9,10 +9,14 @@ using Orchard.Sandbox.Models;
|
||||
namespace Orchard.Sandbox.Controllers {
|
||||
[UsedImplicitly]
|
||||
public class SandboxPageDriver : ItemDriver<SandboxPage> {
|
||||
public SandboxPageDriver()
|
||||
: base(SandboxPage.ContentType) {
|
||||
}
|
||||
public readonly static ContentType ContentType = new ContentType {
|
||||
Name = "sandboxpage",
|
||||
DisplayName = "Sandbox Page"
|
||||
};
|
||||
|
||||
protected override ContentType GetContentType() {
|
||||
return ContentType;
|
||||
}
|
||||
protected override string GetDisplayText(SandboxPage item) {
|
||||
return item.Record.Name;
|
||||
}
|
||||
|
@@ -4,23 +4,21 @@ using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Sandbox.Controllers;
|
||||
|
||||
namespace Orchard.Sandbox.Models {
|
||||
[UsedImplicitly]
|
||||
public class SandboxContentHandler : ContentHandler {
|
||||
public override IEnumerable<ContentType> GetContentTypes() {
|
||||
return new[] { SandboxPage.ContentType };
|
||||
}
|
||||
|
||||
public SandboxContentHandler(
|
||||
IRepository<SandboxPageRecord> pageRepository,
|
||||
IRepository<SandboxSettingsRecord> settingsRepository) {
|
||||
|
||||
// define the "sandboxpage" content type
|
||||
Filters.Add(new ActivatingFilter<SandboxPage>(SandboxPage.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>(SandboxPage.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>(SandboxPage.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>(SandboxPage.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<SandboxPage>(SandboxPageDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>(SandboxPageDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>(SandboxPageDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>(SandboxPageDriver.ContentType.Name));
|
||||
Filters.Add(new StorageFilter<SandboxPageRecord>(pageRepository) { AutomaticallyCreateMissingRecord = true });
|
||||
|
||||
|
||||
|
@@ -4,7 +4,6 @@ using Orchard.ContentManagement;
|
||||
namespace Orchard.Sandbox.Models {
|
||||
public class SandboxPage : ContentPart<SandboxPageRecord> {
|
||||
|
||||
public readonly static ContentType ContentType = new ContentType {Name = "sandboxpage", DisplayName = "Sandbox Page"};
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ namespace Orchard.Users.Controllers {
|
||||
}
|
||||
|
||||
public ActionResult Create() {
|
||||
var user = Services.ContentManager.New<IUser>(Models.User.ContentType.Name);
|
||||
var user = Services.ContentManager.New<IUser>(UserDriver.ContentType.Name);
|
||||
var model = new UserCreateViewModel {
|
||||
User = Services.ContentManager.BuildEditorModel(user)
|
||||
};
|
||||
|
@@ -0,0 +1,41 @@
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Users.Models;
|
||||
|
||||
namespace Orchard.Users.Controllers {
|
||||
[UsedImplicitly]
|
||||
public class UserDriver : ItemDriver<User> {
|
||||
public readonly static ContentType ContentType = new ContentType {
|
||||
Name = "user",
|
||||
DisplayName = "User Profile"
|
||||
};
|
||||
|
||||
protected override ContentType GetContentType() {
|
||||
return ContentType;
|
||||
}
|
||||
|
||||
protected override string GetDisplayText(User item) {
|
||||
//TEMP: need a "display name" probably... showing login info likely not a best practice...
|
||||
return item.UserName;
|
||||
}
|
||||
|
||||
protected override RouteValueDictionary GetEditorRouteValues(User item) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Orchard.Users"},
|
||||
{"Controller", "Admin"},
|
||||
{"Action", "Edit"},
|
||||
{"Id", item.ContentItem.Id},
|
||||
};
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(User part) {
|
||||
return ItemTemplate("Items/Users.User");
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(User part, IUpdateModel updater) {
|
||||
return ItemTemplate("Items/Users.User");
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,8 +3,6 @@ using Orchard.Security;
|
||||
|
||||
namespace Orchard.Users.Models {
|
||||
public sealed class User : ContentPart<UserRecord>, IUser {
|
||||
public readonly static ContentType ContentType = new ContentType { Name = "user", DisplayName = "User Profile" };
|
||||
|
||||
public int Id {
|
||||
get { return ContentItem.Id; }
|
||||
}
|
||||
|
@@ -1,18 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Users.Controllers;
|
||||
|
||||
namespace Orchard.Users.Models {
|
||||
public class UserHandler : ContentHandler {
|
||||
public override IEnumerable<ContentType> GetContentTypes() {
|
||||
return new[] { User.ContentType };
|
||||
}
|
||||
|
||||
public UserHandler(IRepository<UserRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<User>("user"));
|
||||
Filters.Add(new ActivatingFilter<User>(UserDriver.ContentType.Name));
|
||||
Filters.Add(new StorageFilter<UserRecord>(repository));
|
||||
Filters.Add(new ContentItemTemplates<User>("Items/Users.User"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -62,6 +62,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Controllers\UserDriver.cs" />
|
||||
<Compile Include="Models\User.cs" />
|
||||
<Compile Include="Models\UserHandler.cs" />
|
||||
<Compile Include="Models\UserRecord.cs" />
|
||||
|
Reference in New Issue
Block a user