mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Content manager assigning values to definition properties
DefaultContentManager now takes a dependency on IContentDefinitionManager ContentItem.TypeDefinition assigned to ContentTypeDefinition instance when creating ContentPart.TypePartDefinition assigned to ContentTypeDefinition.Part instance as added Empty definition instances are created as code-only types and parts are created --HG-- branch : dev
This commit is contained in:
@@ -6,6 +6,7 @@ using JetBrains.Annotations;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.Core.Common;
|
using Orchard.Core.Common;
|
||||||
using Orchard.Core.Common.Handlers;
|
using Orchard.Core.Common.Handlers;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
@@ -25,6 +26,7 @@ namespace Orchard.Core.Tests.Common.Providers {
|
|||||||
private Mock<IAuthenticationService> _authn;
|
private Mock<IAuthenticationService> _authn;
|
||||||
private Mock<IAuthorizationService> _authz;
|
private Mock<IAuthorizationService> _authz;
|
||||||
private Mock<IMembershipService> _membership;
|
private Mock<IMembershipService> _membership;
|
||||||
|
private Mock<IContentDefinitionManager> _contentDefinitionManager;
|
||||||
|
|
||||||
public override void Register(ContainerBuilder builder) {
|
public override void Register(ContainerBuilder builder) {
|
||||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||||
@@ -35,11 +37,12 @@ namespace Orchard.Core.Tests.Common.Providers {
|
|||||||
_authn = new Mock<IAuthenticationService>();
|
_authn = new Mock<IAuthenticationService>();
|
||||||
_authz = new Mock<IAuthorizationService>();
|
_authz = new Mock<IAuthorizationService>();
|
||||||
_membership = new Mock<IMembershipService>();
|
_membership = new Mock<IMembershipService>();
|
||||||
|
_contentDefinitionManager = new Mock<IContentDefinitionManager>();
|
||||||
|
|
||||||
builder.RegisterInstance(_authn.Object);
|
builder.RegisterInstance(_authn.Object);
|
||||||
builder.RegisterInstance(_authz.Object);
|
builder.RegisterInstance(_authz.Object);
|
||||||
builder.RegisterInstance(_membership.Object);
|
builder.RegisterInstance(_membership.Object);
|
||||||
|
builder.RegisterInstance(_contentDefinitionManager.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<Type> DatabaseTypes {
|
protected override IEnumerable<Type> DatabaseTypes {
|
||||||
|
@@ -2,10 +2,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Drivers;
|
using Orchard.ContentManagement.Drivers;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Core.Common.Services;
|
using Orchard.Core.Common.Services;
|
||||||
@@ -27,6 +29,7 @@ namespace Orchard.Core.Tests.Common.Services {
|
|||||||
public override void Register(ContainerBuilder builder) {
|
public override void Register(ContainerBuilder builder) {
|
||||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||||
|
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||||
|
|
||||||
builder.RegisterType<ThingHandler>().As<IContentHandler>();
|
builder.RegisterType<ThingHandler>().As<IContentHandler>();
|
||||||
builder.RegisterType<StuffHandler>().As<IContentHandler>();
|
builder.RegisterType<StuffHandler>().As<IContentHandler>();
|
||||||
|
@@ -9,6 +9,8 @@ using Moq;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.ContentManagement.MetaData.Builders;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Core.Feeds;
|
using Orchard.Core.Feeds;
|
||||||
using Orchard.Core.Feeds.Controllers;
|
using Orchard.Core.Feeds.Controllers;
|
||||||
@@ -145,7 +147,7 @@ namespace Orchard.Core.Tests.Feeds.Controllers {
|
|||||||
[Test]
|
[Test]
|
||||||
public void CorePartValuesAreExtracted() {
|
public void CorePartValuesAreExtracted() {
|
||||||
var clock = new StubClock();
|
var clock = new StubClock();
|
||||||
var hello = new ContentItemBuilder("hello")
|
var hello = new ContentItemBuilder(new ContentTypeDefinitionBuilder().Named("hello").Build())
|
||||||
.Weld<CommonAspect>()
|
.Weld<CommonAspect>()
|
||||||
.Weld<RoutableAspect>()
|
.Weld<RoutableAspect>()
|
||||||
.Weld<BodyAspect>()
|
.Weld<BodyAspect>()
|
||||||
|
@@ -4,6 +4,7 @@ using Autofac;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.Core.Scheduling.Models;
|
using Orchard.Core.Scheduling.Models;
|
||||||
using Orchard.Core.Scheduling.Services;
|
using Orchard.Core.Scheduling.Services;
|
||||||
@@ -29,6 +30,7 @@ namespace Orchard.Core.Tests.Scheduling {
|
|||||||
builder.RegisterInstance(new Mock<IOrchardServices>().Object);
|
builder.RegisterInstance(new Mock<IOrchardServices>().Object);
|
||||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||||
|
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||||
|
|
||||||
builder.RegisterType<ScheduledTaskExecutor>().As<IBackgroundTask>().Named("ScheduledTaskExecutor", typeof(IBackgroundTask));
|
builder.RegisterType<ScheduledTaskExecutor>().As<IBackgroundTask>().Named("ScheduledTaskExecutor", typeof(IBackgroundTask));
|
||||||
builder.RegisterInstance(_handler).As<IScheduledTaskHandler>();
|
builder.RegisterInstance(_handler).As<IScheduledTaskHandler>();
|
||||||
|
@@ -5,6 +5,7 @@ using Autofac;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.Core.Scheduling.Models;
|
using Orchard.Core.Scheduling.Models;
|
||||||
using Orchard.Core.Scheduling.Services;
|
using Orchard.Core.Scheduling.Services;
|
||||||
@@ -33,6 +34,7 @@ namespace Orchard.Core.Tests.Scheduling {
|
|||||||
builder.RegisterInstance(_mockServices.Object);
|
builder.RegisterInstance(_mockServices.Object);
|
||||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||||
|
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||||
|
|
||||||
builder.RegisterType<ScheduledTaskManager>().As<IScheduledTaskManager>();
|
builder.RegisterType<ScheduledTaskManager>().As<IScheduledTaskManager>();
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
|
using Moq;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
@@ -44,6 +46,7 @@ namespace Orchard.Tests.ContentManagement {
|
|||||||
builder.RegisterModule(new ContentModule());
|
builder.RegisterModule(new ContentModule());
|
||||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>().SingleInstance();
|
builder.RegisterType<DefaultContentManager>().As<IContentManager>().SingleInstance();
|
||||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||||
|
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||||
|
|
||||||
builder.RegisterType<AlphaHandler>().As<IContentHandler>();
|
builder.RegisterType<AlphaHandler>().As<IContentHandler>();
|
||||||
builder.RegisterType<BetaHandler>().As<IContentHandler>();
|
builder.RegisterType<BetaHandler>().As<IContentHandler>();
|
||||||
|
@@ -2,8 +2,11 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
|
using Moq;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.ContentManagement.MetaData.Builders;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
@@ -18,6 +21,7 @@ namespace Orchard.Tests.ContentManagement {
|
|||||||
private IContentManager _manager;
|
private IContentManager _manager;
|
||||||
private ISessionFactory _sessionFactory;
|
private ISessionFactory _sessionFactory;
|
||||||
private ISession _session;
|
private ISession _session;
|
||||||
|
private Mock<IContentDefinitionManager> _contentDefinitionManager;
|
||||||
|
|
||||||
[TestFixtureSetUp]
|
[TestFixtureSetUp]
|
||||||
public void InitFixture() {
|
public void InitFixture() {
|
||||||
@@ -39,10 +43,12 @@ namespace Orchard.Tests.ContentManagement {
|
|||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Init() {
|
public void Init() {
|
||||||
|
_contentDefinitionManager = new Mock<IContentDefinitionManager>();
|
||||||
|
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
//builder.RegisterModule(new ImplicitCollectionSupportModule());
|
|
||||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||||
|
builder.RegisterInstance(_contentDefinitionManager.Object);
|
||||||
|
|
||||||
builder.RegisterType<AlphaHandler>().As<IContentHandler>();
|
builder.RegisterType<AlphaHandler>().As<IContentHandler>();
|
||||||
builder.RegisterType<BetaHandler>().As<IContentHandler>();
|
builder.RegisterType<BetaHandler>().As<IContentHandler>();
|
||||||
@@ -459,6 +465,40 @@ namespace Orchard.Tests.ContentManagement {
|
|||||||
Assert.That(gammas[3].Version, Is.EqualTo(4));
|
Assert.That(gammas[3].Version, Is.EqualTo(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmptyTypeDefinitionShouldBeCreatedIfNotAlreadyDefined() {
|
||||||
|
var contentItem = _manager.New("no-such-type");
|
||||||
|
Assert.That(contentItem.ContentType, Is.EqualTo("no-such-type"));
|
||||||
|
Assert.That(contentItem.TypeDefinition, Is.Not.Null);
|
||||||
|
Assert.That(contentItem.TypeDefinition.Name, Is.EqualTo("no-such-type"));
|
||||||
|
Assert.That(contentItem.TypeDefinition.Settings.Count(), Is.EqualTo(0));
|
||||||
|
Assert.That(contentItem.TypeDefinition.Parts.Count(), Is.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ExistingTypeAndPartDefinitionShouldBeUsed() {
|
||||||
|
var alphaType = new ContentTypeDefinitionBuilder()
|
||||||
|
.Named("alpha")
|
||||||
|
.WithSetting("x", "1")
|
||||||
|
.WithPart("foo")
|
||||||
|
.WithPart("Flavored", part => part.WithSetting("spin", "clockwise"))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_contentDefinitionManager
|
||||||
|
.Setup(x => x.GetTypeDefinition("alpha"))
|
||||||
|
.Returns(alphaType);
|
||||||
|
|
||||||
|
var contentItem = _manager.New("alpha");
|
||||||
|
Assert.That(contentItem.ContentType, Is.EqualTo("alpha"));
|
||||||
|
Assert.That(contentItem.TypeDefinition, Is.Not.Null);
|
||||||
|
Assert.That(contentItem.TypeDefinition, Is.SameAs(alphaType));
|
||||||
|
|
||||||
|
var flavored = contentItem.As<Flavored>();
|
||||||
|
Assert.That(flavored, Is.Not.Null);
|
||||||
|
Assert.That(flavored.TypePartDefinition, Is.Not.Null);
|
||||||
|
Assert.That(flavored.TypePartDefinition.Settings["spin"], Is.EqualTo("clockwise"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.ContentManagement.MetaData.Builders;
|
||||||
|
|
||||||
namespace Orchard.Tests.ContentManagement.Handlers {
|
namespace Orchard.Tests.ContentManagement.Handlers {
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ namespace Orchard.Tests.ContentManagement.Handlers {
|
|||||||
public void PartShouldBeAddedBasedOnSimplePredicate() {
|
public void PartShouldBeAddedBasedOnSimplePredicate() {
|
||||||
var modelDriver = new TestModelHandler();
|
var modelDriver = new TestModelHandler();
|
||||||
|
|
||||||
var builder = new ContentItemBuilder("testing");
|
var builder = new ContentItemBuilder(new ContentTypeDefinitionBuilder().Named("testing").Build());
|
||||||
((IContentHandler)modelDriver).Activating(new ActivatingContentContext { Builder = builder, ContentType = "testing" });
|
((IContentHandler)modelDriver).Activating(new ActivatingContentContext { Builder = builder, ContentType = "testing" });
|
||||||
var model = builder.Build();
|
var model = builder.Build();
|
||||||
Assert.That(model.Is<TestModelPart>(), Is.True);
|
Assert.That(model.Is<TestModelPart>(), Is.True);
|
||||||
|
@@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.ContentManagement.MetaData.Builders;
|
||||||
using Orchard.Tests.ContentManagement.Models;
|
using Orchard.Tests.ContentManagement.Models;
|
||||||
|
|
||||||
namespace Orchard.Tests.ContentManagement.Handlers {
|
namespace Orchard.Tests.ContentManagement.Handlers {
|
||||||
@@ -12,21 +13,21 @@ namespace Orchard.Tests.ContentManagement.Handlers {
|
|||||||
public class ModelBuilderTests {
|
public class ModelBuilderTests {
|
||||||
[Test]
|
[Test]
|
||||||
public void BuilderShouldReturnWorkingModelWithTypeAndId() {
|
public void BuilderShouldReturnWorkingModelWithTypeAndId() {
|
||||||
var builder = new ContentItemBuilder("foo");
|
var builder = new ContentItemBuilder(new ContentTypeDefinitionBuilder().Named("foo").Build());
|
||||||
var model = builder.Build();
|
var model = builder.Build();
|
||||||
Assert.That(model.ContentType, Is.EqualTo("foo"));
|
Assert.That(model.ContentType, Is.EqualTo("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IdShouldDefaultToZero() {
|
public void IdShouldDefaultToZero() {
|
||||||
var builder = new ContentItemBuilder("foo");
|
var builder = new ContentItemBuilder(new ContentTypeDefinitionBuilder().Named("foo").Build());
|
||||||
var model = builder.Build();
|
var model = builder.Build();
|
||||||
Assert.That(model.Id, Is.EqualTo(0));
|
Assert.That(model.Id, Is.EqualTo(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void WeldShouldAddPartToModel() {
|
public void WeldShouldAddPartToModel() {
|
||||||
var builder = new ContentItemBuilder("foo");
|
var builder = new ContentItemBuilder(new ContentTypeDefinitionBuilder().Named("foo").Build());
|
||||||
builder.Weld<Alpha>();
|
builder.Weld<Alpha>();
|
||||||
var model = builder.Build();
|
var model = builder.Build();
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@ namespace Orchard.Core.Routable.Controllers {
|
|||||||
if (string.IsNullOrEmpty(matchedPath)) {
|
if (string.IsNullOrEmpty(matchedPath)) {
|
||||||
throw new ApplicationException("404 - should not have passed path constraint");
|
throw new ApplicationException("404 - should not have passed path constraint");
|
||||||
}
|
}
|
||||||
|
|
||||||
var hits = _contentManager
|
var hits = _contentManager
|
||||||
.Query<IsRoutable, RoutableRecord>(VersionOptions.Published)
|
.Query<IsRoutable, RoutableRecord>(VersionOptions.Published)
|
||||||
.Where(r => r.Path == matchedPath)
|
.Where(r => r.Path == matchedPath)
|
||||||
|
@@ -1,12 +1,14 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.ContentManagement.MetaData.Builders;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
|
|
||||||
namespace Orchard.Roles.Models {
|
namespace Orchard.Roles.Models {
|
||||||
public static class UserSimulation {
|
public static class UserSimulation {
|
||||||
public static IUser Create(string role) {
|
public static IUser Create(string role) {
|
||||||
var simulation = new ContentItemBuilder("user")
|
var simulationType = new ContentTypeDefinitionBuilder().Named("user").Build();
|
||||||
|
var simulation = new ContentItemBuilder(simulationType)
|
||||||
.Weld<SimulatedUser>()
|
.Weld<SimulatedUser>()
|
||||||
.Weld<SimulatedUserRoles>()
|
.Weld<SimulatedUserRoles>()
|
||||||
.Build();
|
.Build();
|
||||||
|
@@ -7,6 +7,7 @@ using Orchard.Commands;
|
|||||||
using Orchard.Commands.Builtin;
|
using Orchard.Commands.Builtin;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.ContentManagement.MetaData.Builders;
|
||||||
using Orchard.Data.Builders;
|
using Orchard.Data.Builders;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@@ -90,7 +91,8 @@ namespace Orchard.Setup {
|
|||||||
|
|
||||||
class SafeModeSiteService : ISiteService {
|
class SafeModeSiteService : ISiteService {
|
||||||
public ISite GetSiteSettings() {
|
public ISite GetSiteSettings() {
|
||||||
var site = new ContentItemBuilder("site")
|
var siteType = new ContentTypeDefinitionBuilder().Named("site").Build();
|
||||||
|
var site = new ContentItemBuilder(siteType)
|
||||||
.Weld<SafeModeSite>()
|
.Weld<SafeModeSite>()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
@@ -4,9 +4,9 @@ using Orchard.ContentManagement.Utilities;
|
|||||||
namespace Orchard.ContentManagement {
|
namespace Orchard.ContentManagement {
|
||||||
public abstract class ContentPart : IContent {
|
public abstract class ContentPart : IContent {
|
||||||
public virtual ContentItem ContentItem { get; set; }
|
public virtual ContentItem ContentItem { get; set; }
|
||||||
public ContentTypeDefinition TypeDefinition { get; set; }
|
public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } }
|
||||||
public ContentTypeDefinition.Part TypePartDefinition { get; set; }
|
public ContentTypeDefinition.Part TypePartDefinition { get; set; }
|
||||||
public ContentPartDefinition PartDefinition { get; set; }
|
public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ContentPart<TRecord> : ContentPart {
|
public class ContentPart<TRecord> : ContentPart {
|
||||||
|
@@ -3,6 +3,9 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.ContentManagement.MetaData.Builders;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
@@ -13,6 +16,7 @@ namespace Orchard.ContentManagement {
|
|||||||
private readonly IRepository<ContentTypeRecord> _contentTypeRepository;
|
private readonly IRepository<ContentTypeRecord> _contentTypeRepository;
|
||||||
private readonly IRepository<ContentItemRecord> _contentItemRepository;
|
private readonly IRepository<ContentItemRecord> _contentItemRepository;
|
||||||
private readonly IRepository<ContentItemVersionRecord> _contentItemVersionRepository;
|
private readonly IRepository<ContentItemVersionRecord> _contentItemVersionRepository;
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
private readonly Func<IContentManagerSession> _contentManagerSession;
|
private readonly Func<IContentManagerSession> _contentManagerSession;
|
||||||
|
|
||||||
public DefaultContentManager(
|
public DefaultContentManager(
|
||||||
@@ -20,11 +24,13 @@ namespace Orchard.ContentManagement {
|
|||||||
IRepository<ContentTypeRecord> contentTypeRepository,
|
IRepository<ContentTypeRecord> contentTypeRepository,
|
||||||
IRepository<ContentItemRecord> contentItemRepository,
|
IRepository<ContentItemRecord> contentItemRepository,
|
||||||
IRepository<ContentItemVersionRecord> contentItemVersionRepository,
|
IRepository<ContentItemVersionRecord> contentItemVersionRepository,
|
||||||
|
IContentDefinitionManager contentDefinitionManager,
|
||||||
Func<IContentManagerSession> contentManagerSession) {
|
Func<IContentManagerSession> contentManagerSession) {
|
||||||
_context = context;
|
_context = context;
|
||||||
_contentTypeRepository = contentTypeRepository;
|
_contentTypeRepository = contentTypeRepository;
|
||||||
_contentItemRepository = contentItemRepository;
|
_contentItemRepository = contentItemRepository;
|
||||||
_contentItemVersionRepository = contentItemVersionRepository;
|
_contentItemVersionRepository = contentItemVersionRepository;
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
_contentManagerSession = contentManagerSession;
|
_contentManagerSession = contentManagerSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,11 +50,16 @@ namespace Orchard.ContentManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public virtual ContentItem New(string contentType) {
|
public virtual ContentItem New(string contentType) {
|
||||||
|
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
|
||||||
|
if (contentTypeDefinition == null) {
|
||||||
|
contentTypeDefinition = new ContentTypeDefinitionBuilder().Named(contentType).Build();
|
||||||
|
}
|
||||||
|
|
||||||
// create a new kernel for the model instance
|
// create a new kernel for the model instance
|
||||||
var context = new ActivatingContentContext {
|
var context = new ActivatingContentContext {
|
||||||
ContentType = contentType,
|
ContentType = contentTypeDefinition.Name,
|
||||||
Builder = new ContentItemBuilder(contentType)
|
Definition = contentTypeDefinition,
|
||||||
|
Builder = new ContentItemBuilder(contentTypeDefinition)
|
||||||
};
|
};
|
||||||
|
|
||||||
// invoke handlers to weld aspects onto kernel
|
// invoke handlers to weld aspects onto kernel
|
||||||
@@ -337,16 +348,16 @@ namespace Orchard.ContentManagement {
|
|||||||
handler.Created(context);
|
handler.Created(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options.IsPublished) {
|
if (options.IsPublished) {
|
||||||
var publishContext = new PublishContentContext(contentItem, null);
|
var publishContext = new PublishContentContext(contentItem, null);
|
||||||
|
|
||||||
// invoke handlers to acquire state, or at least establish lazy loading callbacks
|
// invoke handlers to acquire state, or at least establish lazy loading callbacks
|
||||||
foreach ( var handler in Handlers ) {
|
foreach (var handler in Handlers) {
|
||||||
handler.Publishing(publishContext);
|
handler.Publishing(publishContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
// invoke handlers to acquire state, or at least establish lazy loading callbacks
|
// invoke handlers to acquire state, or at least establish lazy loading callbacks
|
||||||
foreach ( var handler in Handlers ) {
|
foreach (var handler in Handlers) {
|
||||||
handler.Published(publishContext);
|
handler.Published(publishContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,19 +31,19 @@ namespace Orchard.ContentManagement.Drivers {
|
|||||||
return part == null ? null : Editor(part, context.Updater);
|
return part == null ? null : Editor(part, context.Updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual DriverResult Display(TContent part, string displayType) {return null;}
|
protected virtual DriverResult Display(TContent part, string displayType) { return null; }
|
||||||
protected virtual DriverResult Editor(TContent part) {return null;}
|
protected virtual DriverResult Editor(TContent part) { return null; }
|
||||||
protected virtual DriverResult Editor(TContent part, IUpdateModel updater) {return null;}
|
protected virtual DriverResult Editor(TContent part, IUpdateModel updater) { return null; }
|
||||||
|
|
||||||
|
|
||||||
public ContentPartTemplateResult ContentPartTemplate(object model) {
|
public ContentPartTemplateResult ContentPartTemplate(object model) {
|
||||||
return new ContentPartTemplateResult(model, null, Prefix).Location(Zone);
|
return new ContentPartTemplateResult(model, null, Prefix).Location(Zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentPartTemplateResult ContentPartTemplate(object model, string template) {
|
public ContentPartTemplateResult ContentPartTemplate(object model, string template) {
|
||||||
return new ContentPartTemplateResult(model, template, Prefix).Location(Zone);
|
return new ContentPartTemplateResult(model, template, Prefix).Location(Zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentPartTemplateResult ContentPartTemplate(object model, string template, string prefix) {
|
public ContentPartTemplateResult ContentPartTemplate(object model, string template, string prefix) {
|
||||||
return new ContentPartTemplateResult(model, template, prefix).Location(Zone);
|
return new ContentPartTemplateResult(model, template, prefix).Location(Zone);
|
||||||
}
|
}
|
||||||
@@ -52,11 +52,12 @@ namespace Orchard.ContentManagement.Drivers {
|
|||||||
return new CombinedResult(results);
|
return new CombinedResult(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ContentPartInfo> GetPartInfo()
|
public IEnumerable<ContentPartInfo> GetPartInfo() {
|
||||||
{
|
var contentPartInfo = new[] {
|
||||||
var contentPartInfo = new List<ContentPartInfo>() {
|
new ContentPartInfo {
|
||||||
new ContentPartInfo()
|
PartName = typeof (TContent).Name,
|
||||||
{PartName = typeof(TContent).Name,Factory = () => new TContent()}
|
Factory = typePartDefinition => new TContent {TypePartDefinition = typePartDefinition}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return contentPartInfo;
|
return contentPartInfo;
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
|
|
||||||
namespace Orchard.ContentManagement.Handlers {
|
namespace Orchard.ContentManagement.Handlers {
|
||||||
public class ActivatingContentContext {
|
public class ActivatingContentContext {
|
||||||
public string ContentType { get; set; }
|
public string ContentType { get; set; }
|
||||||
|
public ContentTypeDefinition Definition { get; set; }
|
||||||
public ContentItemBuilder Builder { get; set; }
|
public ContentItemBuilder Builder { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,18 @@
|
|||||||
namespace Orchard.ContentManagement.Handlers {
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
|
|
||||||
|
namespace Orchard.ContentManagement.Handlers {
|
||||||
public class ContentItemBuilder {
|
public class ContentItemBuilder {
|
||||||
|
private readonly ContentTypeDefinition _definition;
|
||||||
private readonly ContentItem _item;
|
private readonly ContentItem _item;
|
||||||
|
|
||||||
public ContentItemBuilder(string contentType) {
|
public ContentItemBuilder(ContentTypeDefinition definition) {
|
||||||
_item = new ContentItem { ContentType = contentType };
|
_definition = definition;
|
||||||
|
_item = new ContentItem {
|
||||||
|
ContentType = definition.Name,
|
||||||
|
TypeDefinition = definition
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentItem Build() {
|
public ContentItem Build() {
|
||||||
@@ -11,7 +20,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ContentItemBuilder Weld<TPart>() where TPart : ContentPart, new() {
|
public ContentItemBuilder Weld<TPart>() where TPart : ContentPart, new() {
|
||||||
var part = new TPart();
|
var partName = typeof(TPart).Name;
|
||||||
|
|
||||||
|
var typePartDefinition = _definition.Parts.FirstOrDefault(p => p.PartDefinition.Name == partName);
|
||||||
|
if (typePartDefinition == null) {
|
||||||
|
typePartDefinition = new ContentTypeDefinition.Part(
|
||||||
|
new ContentPartDefinition(partName),
|
||||||
|
new Dictionary<string, string>());
|
||||||
|
}
|
||||||
|
|
||||||
|
var part = new TPart {
|
||||||
|
TypePartDefinition = typePartDefinition
|
||||||
|
};
|
||||||
_item.Weld(part);
|
_item.Weld(part);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -20,6 +40,5 @@
|
|||||||
_item.Weld(contentPart);
|
_item.Weld(contentPart);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,14 +14,15 @@ namespace Orchard.ContentManagement.MetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Activating(ActivatingContentContext context) {
|
public override void Activating(ActivatingContentContext context) {
|
||||||
var contentTypeRecord = _contentDefinitionManager.GetTypeDefinition(context.ContentType);
|
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType);
|
||||||
if (contentTypeRecord == null)
|
if (contentTypeDefinition == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach(var partInfo in _contentPartDrivers.SelectMany(cpp => cpp.GetPartInfo())) {
|
foreach (var partInfo in _contentPartDrivers.SelectMany(cpp => cpp.GetPartInfo())) {
|
||||||
var partName = partInfo.PartName;
|
var partName = partInfo.PartName;
|
||||||
if (contentTypeRecord.Parts.Any(p=>p.PartDefinition.Name == partName)) {
|
var typePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == partName);
|
||||||
context.Builder.Weld(partInfo.Factory());
|
if (typePartDefinition != null) {
|
||||||
|
context.Builder.Weld(partInfo.Factory(typePartDefinition));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
|
|
||||||
namespace Orchard.ContentManagement.MetaData
|
namespace Orchard.ContentManagement.MetaData {
|
||||||
{
|
public class ContentPartInfo {
|
||||||
public class ContentPartInfo
|
|
||||||
{
|
|
||||||
public string PartName { get; set; }
|
public string PartName { get; set; }
|
||||||
public Func<ContentPart> Factory { get; set; }
|
public Func<ContentTypeDefinition.Part, ContentPart> Factory { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user