mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
Adding ContentType class and GetContentTypes methods to IContentManager and IContentProvider
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042626
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Autofac.Builder;
|
using Autofac.Builder;
|
||||||
using Autofac.Modules;
|
using Autofac.Modules;
|
||||||
@@ -149,6 +150,15 @@ namespace Orchard.Tests.Models {
|
|||||||
Assert.That(modelRecord.ContentType.Name, Is.EqualTo("beta"));
|
Assert.That(modelRecord.ContentType.Name, Is.EqualTo("beta"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetContentTypesShouldReturnAllTypes() {
|
||||||
|
var types = _manager.GetContentTypes();
|
||||||
|
Assert.That(types.Count(), Is.EqualTo(3));
|
||||||
|
Assert.That(types, Has.Some.With.Property("Name").EqualTo("alpha"));
|
||||||
|
Assert.That(types, Has.Some.With.Property("Name").EqualTo("beta"));
|
||||||
|
Assert.That(types, Has.Some.With.Property("Name").EqualTo("gamma"));
|
||||||
|
}
|
||||||
|
|
||||||
private ContentItemRecord CreateModelRecord(string contentType) {
|
private ContentItemRecord CreateModelRecord(string contentType) {
|
||||||
var contentItemRepository = _container.Resolve<IRepository<ContentItemRecord>>();
|
var contentItemRepository = _container.Resolve<IRepository<ContentItemRecord>>();
|
||||||
var contentTypeRepository = _container.Resolve<IRepository<ContentTypeRecord>>();
|
var contentTypeRepository = _container.Resolve<IRepository<ContentTypeRecord>>();
|
||||||
|
@@ -1,7 +1,11 @@
|
|||||||
using Orchard.Models.Driver;
|
using Orchard.Models;
|
||||||
|
using Orchard.Models.Driver;
|
||||||
|
|
||||||
namespace Orchard.Tests.Models.Stubs {
|
namespace Orchard.Tests.Models.Stubs {
|
||||||
public class AlphaProvider : ContentProvider {
|
public class AlphaProvider : ContentProvider {
|
||||||
|
public override System.Collections.Generic.IEnumerable<Orchard.Models.ContentType> GetContentTypes() {
|
||||||
|
return new[] {new ContentType {Name = "alpha"}};
|
||||||
|
}
|
||||||
protected override void Activating(ActivatingContentContext context) {
|
protected override void Activating(ActivatingContentContext context) {
|
||||||
if (context.ContentType == "alpha") {
|
if (context.ContentType == "alpha") {
|
||||||
context.Builder.Weld<Alpha>();
|
context.Builder.Weld<Alpha>();
|
||||||
|
@@ -2,10 +2,15 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Orchard.Models;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
|
|
||||||
namespace Orchard.Tests.Models.Stubs {
|
namespace Orchard.Tests.Models.Stubs {
|
||||||
public class BetaProvider : ContentProvider {
|
public class BetaProvider : ContentProvider {
|
||||||
|
public override System.Collections.Generic.IEnumerable<Orchard.Models.ContentType> GetContentTypes() {
|
||||||
|
return new[] { new ContentType { Name = "beta" } };
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Activating(ActivatingContentContext context) {
|
protected override void Activating(ActivatingContentContext context) {
|
||||||
if (context.ContentType == "beta") {
|
if (context.ContentType == "beta") {
|
||||||
context.Builder.Weld<Beta>();
|
context.Builder.Weld<Beta>();
|
||||||
|
@@ -13,6 +13,10 @@ namespace Orchard.Tests.Models.Stubs {
|
|||||||
|
|
||||||
|
|
||||||
public class DeltaProvider : ContentProvider {
|
public class DeltaProvider : ContentProvider {
|
||||||
|
public override System.Collections.Generic.IEnumerable<Orchard.Models.ContentType> GetContentTypes() {
|
||||||
|
return new[] { new ContentType { Name = "delta" } };
|
||||||
|
}
|
||||||
|
|
||||||
public DeltaProvider(IRepository<DeltaRecord> repository) {
|
public DeltaProvider(IRepository<DeltaRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<Delta>(x => x == "delta"));
|
Filters.Add(new ActivatingFilter<Delta>(x => x == "delta"));
|
||||||
Filters.Add(new StorageFilter<DeltaRecord>(repository));
|
Filters.Add(new StorageFilter<DeltaRecord>(repository));
|
||||||
|
@@ -12,6 +12,10 @@ namespace Orchard.Tests.Models.Stubs {
|
|||||||
|
|
||||||
|
|
||||||
public class GammaProvider : ContentProvider {
|
public class GammaProvider : ContentProvider {
|
||||||
|
public override System.Collections.Generic.IEnumerable<Orchard.Models.ContentType> GetContentTypes() {
|
||||||
|
return new[] { new ContentType { Name = "gamma" } };
|
||||||
|
}
|
||||||
|
|
||||||
public GammaProvider(IRepository<GammaRecord> repository) {
|
public GammaProvider(IRepository<GammaRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<Gamma>(x => x == "gamma"));
|
Filters.Add(new ActivatingFilter<Gamma>(x => x == "gamma"));
|
||||||
Filters.Add(new StorageFilter<GammaRecord>(repository));
|
Filters.Add(new StorageFilter<GammaRecord>(repository));
|
||||||
|
@@ -4,6 +4,8 @@ using Orchard.Settings;
|
|||||||
|
|
||||||
namespace Orchard.Core.Settings.Models {
|
namespace Orchard.Core.Settings.Models {
|
||||||
public sealed class SiteSettings : ContentPart<SiteSettingsRecord>, ISite {
|
public sealed class SiteSettings : ContentPart<SiteSettingsRecord>, ISite {
|
||||||
|
public static readonly ContentType ContentType = new ContentType{Name="site", DisplayName="Site Settings"};
|
||||||
|
|
||||||
public string SiteName {
|
public string SiteName {
|
||||||
get { return Record.SiteName; }
|
get { return Record.SiteName; }
|
||||||
set { Record.SiteName = value; }
|
set { Record.SiteName = value; }
|
||||||
|
@@ -1,9 +1,16 @@
|
|||||||
using Orchard.Core.Settings.Records;
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Core.Settings.Records;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
|
using Orchard.Models;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
|
|
||||||
namespace Orchard.Core.Settings.Models {
|
namespace Orchard.Core.Settings.Models {
|
||||||
public class SiteSettingsProvider : ContentProvider {
|
public class SiteSettingsProvider : ContentProvider {
|
||||||
|
|
||||||
|
public override IEnumerable<ContentType> GetContentTypes() {
|
||||||
|
return new[] {SiteSettings.ContentType};
|
||||||
|
}
|
||||||
|
|
||||||
public SiteSettingsProvider(IRepository<SiteSettingsRecord> repository){
|
public SiteSettingsProvider(IRepository<SiteSettingsRecord> repository){
|
||||||
Filters.Add(new ActivatingFilter<SiteSettings>("site"));
|
Filters.Add(new ActivatingFilter<SiteSettings>("site"));
|
||||||
Filters.Add(new StorageFilter<SiteSettingsRecord>(repository));
|
Filters.Add(new StorageFilter<SiteSettingsRecord>(repository));
|
||||||
|
@@ -3,6 +3,8 @@ using Orchard.Models;
|
|||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class Blog : ContentPart<BlogRecord> {
|
public class Blog : ContentPart<BlogRecord> {
|
||||||
|
public readonly static ContentType ContentType = new ContentType { Name = "blog", DisplayName = "Blog" };
|
||||||
|
|
||||||
public int Id { get { return ContentItem.Id; } }
|
public int Id { get { return ContentItem.Id; } }
|
||||||
public string Name { get { return this.As<RoutableAspect>().Title; } }
|
public string Name { get { return this.As<RoutableAspect>().Title; } }
|
||||||
public string Slug { get { return this.As<RoutableAspect>().Slug; } }
|
public string Slug { get { return this.As<RoutableAspect>().Slug; } }
|
||||||
|
@@ -5,6 +5,8 @@ using Orchard.Security;
|
|||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogPost : ContentPart<BlogPostRecord> {
|
public class BlogPost : ContentPart<BlogPostRecord> {
|
||||||
|
public readonly static ContentType ContentType = new ContentType { Name = "blogpost", DisplayName = "Blog Post" };
|
||||||
|
|
||||||
public Blog Blog { get; set; }
|
public Blog Blog { get; set; }
|
||||||
public string Title { get { return this.As<RoutableAspect>().Title; } }
|
public string Title { get { return this.As<RoutableAspect>().Title; } }
|
||||||
public string Body { get { return this.As<BodyAspect>().Body; } }
|
public string Body { get { return this.As<BodyAspect>().Body; } }
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Models;
|
using Orchard.Models;
|
||||||
@@ -5,6 +6,10 @@ using Orchard.Models.Driver;
|
|||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogPostProvider : ContentProvider {
|
public class BlogPostProvider : ContentProvider {
|
||||||
|
public override IEnumerable<ContentType> GetContentTypes() {
|
||||||
|
return new[] { BlogPost.ContentType };
|
||||||
|
}
|
||||||
|
|
||||||
public BlogPostProvider(IRepository<BlogPostRecord> repository, IContentManager contentManager) {
|
public BlogPostProvider(IRepository<BlogPostRecord> repository, IContentManager contentManager) {
|
||||||
Filters.Add(new ActivatingFilter<BlogPost>("blogpost"));
|
Filters.Add(new ActivatingFilter<BlogPost>("blogpost"));
|
||||||
Filters.Add(new ActivatingFilter<CommonAspect>("blogpost"));
|
Filters.Add(new ActivatingFilter<CommonAspect>("blogpost"));
|
||||||
|
@@ -1,9 +1,15 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
|
using Orchard.Models;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogProvider : ContentProvider {
|
public class BlogProvider : ContentProvider {
|
||||||
|
public override IEnumerable<ContentType> GetContentTypes() {
|
||||||
|
return new[] { Blog.ContentType };
|
||||||
|
}
|
||||||
|
|
||||||
public BlogProvider(IRepository<BlogRecord> repository) {
|
public BlogProvider(IRepository<BlogRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<Blog>("blog"));
|
Filters.Add(new ActivatingFilter<Blog>("blog"));
|
||||||
Filters.Add(new ActivatingFilter<CommonAspect>("blog"));
|
Filters.Add(new ActivatingFilter<CommonAspect>("blog"));
|
||||||
|
@@ -1,19 +1,25 @@
|
|||||||
using Orchard.Core.Common.Models;
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Models;
|
using Orchard.Models;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
|
|
||||||
namespace Orchard.Sandbox.Models {
|
namespace Orchard.Sandbox.Models {
|
||||||
public class SandboxContentProvider : ContentProvider {
|
public class SandboxContentProvider : ContentProvider {
|
||||||
|
|
||||||
|
public override IEnumerable<ContentType> GetContentTypes() {
|
||||||
|
return new[] {SandboxPage.ContentType};
|
||||||
|
}
|
||||||
|
|
||||||
public SandboxContentProvider(
|
public SandboxContentProvider(
|
||||||
IRepository<SandboxPageRecord> pageRepository,
|
IRepository<SandboxPageRecord> pageRepository,
|
||||||
IRepository<SandboxSettingsRecord> settingsRepository) {
|
IRepository<SandboxSettingsRecord> settingsRepository) {
|
||||||
|
|
||||||
// define the "sandboxpage" content type
|
// define the "sandboxpage" content type
|
||||||
Filters.Add(new ActivatingFilter<SandboxPage>("sandboxpage"));
|
Filters.Add(new ActivatingFilter<SandboxPage>(SandboxPage.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<CommonAspect>("sandboxpage"));
|
Filters.Add(new ActivatingFilter<CommonAspect>(SandboxPage.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<RoutableAspect>("sandboxpage"));
|
Filters.Add(new ActivatingFilter<RoutableAspect>(SandboxPage.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<BodyAspect>("sandboxpage"));
|
Filters.Add(new ActivatingFilter<BodyAspect>(SandboxPage.ContentType.Name));
|
||||||
Filters.Add(new StorageFilter<SandboxPageRecord>(pageRepository) { AutomaticallyCreateMissingRecord = true });
|
Filters.Add(new StorageFilter<SandboxPageRecord>(pageRepository) { AutomaticallyCreateMissingRecord = true });
|
||||||
|
|
||||||
// add settings to site, and simple record-template gui
|
// add settings to site, and simple record-template gui
|
||||||
|
@@ -4,6 +4,8 @@ using Orchard.Models;
|
|||||||
namespace Orchard.Sandbox.Models {
|
namespace Orchard.Sandbox.Models {
|
||||||
public class SandboxPage : ContentPart<SandboxPageRecord>, IContentDisplayInfo {
|
public class SandboxPage : ContentPart<SandboxPageRecord>, IContentDisplayInfo {
|
||||||
|
|
||||||
|
public readonly static ContentType ContentType = new ContentType {Name = "sandboxpage", DisplayName = "Sandbox Page"};
|
||||||
|
|
||||||
string IContentDisplayInfo.DisplayText {
|
string IContentDisplayInfo.DisplayText {
|
||||||
get { return Record.Name; }
|
get { return Record.Name; }
|
||||||
}
|
}
|
||||||
@@ -17,4 +19,4 @@ namespace Orchard.Sandbox.Models {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,8 @@ using Orchard.Security;
|
|||||||
|
|
||||||
namespace Orchard.Users.Models {
|
namespace Orchard.Users.Models {
|
||||||
public sealed class User : ContentPart<UserRecord>, IUser {
|
public sealed class User : ContentPart<UserRecord>, IUser {
|
||||||
|
public readonly static ContentType ContentType = new ContentType { Name = "user", DisplayName = "User Profile" };
|
||||||
|
|
||||||
public int Id {
|
public int Id {
|
||||||
get { return ContentItem.Id; }
|
get { return ContentItem.Id; }
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,14 @@
|
|||||||
using Orchard.Data;
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Data;
|
||||||
|
using Orchard.Models;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
|
|
||||||
namespace Orchard.Users.Models {
|
namespace Orchard.Users.Models {
|
||||||
public class UserProvider : ContentProvider {
|
public class UserProvider : ContentProvider {
|
||||||
|
public override IEnumerable<ContentType> GetContentTypes() {
|
||||||
|
return new[] { User.ContentType };
|
||||||
|
}
|
||||||
|
|
||||||
public UserProvider(IRepository<UserRecord> repository) {
|
public UserProvider(IRepository<UserRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<User>("user"));
|
Filters.Add(new ActivatingFilter<User>("user"));
|
||||||
Filters.Add(new StorageFilter<UserRecord>(repository));
|
Filters.Add(new StorageFilter<UserRecord>(repository));
|
||||||
|
11
src/Orchard/Models/ContentType.cs
Normal file
11
src/Orchard/Models/ContentType.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Orchard.Models {
|
||||||
|
public class ContentType {
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string DisplayName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
@@ -31,6 +30,12 @@ namespace Orchard.Models {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<ContentType> GetContentTypes() {
|
||||||
|
return Drivers.Aggregate(
|
||||||
|
Enumerable.Empty<ContentType>(),
|
||||||
|
(contentTypes, contentProvider) => contentTypes.Concat(contentProvider.GetContentTypes()));
|
||||||
|
}
|
||||||
|
|
||||||
public virtual ContentItem New(string contentType) {
|
public virtual ContentItem New(string contentType) {
|
||||||
|
|
||||||
// create a new kernel for the model instance
|
// create a new kernel for the model instance
|
||||||
|
@@ -34,6 +34,10 @@ namespace Orchard.Models.Driver {
|
|||||||
protected override void Loaded(LoadContentContext context, TPart instance) { if (OnLoaded != null) OnLoaded(context, instance); }
|
protected override void Loaded(LoadContentContext context, TPart instance) { if (OnLoaded != null) OnLoaded(context, instance); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual IEnumerable<ContentType> GetContentTypes() {
|
||||||
|
return Enumerable.Empty<ContentType>();
|
||||||
|
}
|
||||||
|
|
||||||
void IContentProvider.Activating(ActivatingContentContext context) {
|
void IContentProvider.Activating(ActivatingContentContext context) {
|
||||||
foreach (var filter in Filters.OfType<IContentActivatingFilter>())
|
foreach (var filter in Filters.OfType<IContentActivatingFilter>())
|
||||||
filter.Activating(context);
|
filter.Activating(context);
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
namespace Orchard.Models.Driver {
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Orchard.Models.Driver {
|
||||||
public interface IContentProvider : IDependency {
|
public interface IContentProvider : IDependency {
|
||||||
|
IEnumerable<ContentType> GetContentTypes();
|
||||||
|
|
||||||
void Activating(ActivatingContentContext context);
|
void Activating(ActivatingContentContext context);
|
||||||
void Activated(ActivatedContentContext context);
|
void Activated(ActivatedContentContext context);
|
||||||
void Creating(CreateContentContext context);
|
void Creating(CreateContentContext context);
|
||||||
|
@@ -5,6 +5,8 @@ using Orchard.UI.Models;
|
|||||||
|
|
||||||
namespace Orchard.Models {
|
namespace Orchard.Models {
|
||||||
public interface IContentManager : IDependency {
|
public interface IContentManager : IDependency {
|
||||||
|
IEnumerable<ContentType> GetContentTypes();
|
||||||
|
|
||||||
ContentItem New(string contentType);
|
ContentItem New(string contentType);
|
||||||
void Create(ContentItem contentItem);
|
void Create(ContentItem contentItem);
|
||||||
|
|
||||||
|
@@ -129,6 +129,7 @@
|
|||||||
<Compile Include="Models\Aspects\ICommonAspect.cs" />
|
<Compile Include="Models\Aspects\ICommonAspect.cs" />
|
||||||
<Compile Include="Models\ContentItem.cs" />
|
<Compile Include="Models\ContentItem.cs" />
|
||||||
<Compile Include="Models\ContentModule.cs" />
|
<Compile Include="Models\ContentModule.cs" />
|
||||||
|
<Compile Include="Models\ContentType.cs" />
|
||||||
<Compile Include="Models\DefaultContentQuery.cs" />
|
<Compile Include="Models\DefaultContentQuery.cs" />
|
||||||
<Compile Include="Models\Driver\ActivatedContentContext.cs" />
|
<Compile Include="Models\Driver\ActivatedContentContext.cs" />
|
||||||
<Compile Include="Models\Driver\ActivatingFilter.cs" />
|
<Compile Include="Models\Driver\ActivatingFilter.cs" />
|
||||||
|
Reference in New Issue
Block a user