mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
IdentityPart as a last resort GUID for references.
Adding it to htmlwidget and comment. --HG-- branch : dev
This commit is contained in:
30
src/Orchard.Web/Core/Common/Drivers/IdentityPartDriver.cs
Normal file
30
src/Orchard.Web/Core/Common/Drivers/IdentityPartDriver.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Core.Common.Drivers {
|
||||
[UsedImplicitly]
|
||||
public class IdentityPartDriver : ContentPartDriver<IdentityPart> {
|
||||
public IdentityPartDriver() {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override string Prefix {
|
||||
get { return "Identity"; }
|
||||
}
|
||||
|
||||
protected override void Importing(IdentityPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var identity = context.Attribute(part.PartDefinition.Name, "Identifier");
|
||||
if (identity != null) {
|
||||
part.Identifier = identity;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(IdentityPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Identifier", part.Identifier);
|
||||
}
|
||||
}
|
||||
}
|
28
src/Orchard.Web/Core/Common/Handlers/IdentityPartHandler.cs
Normal file
28
src/Orchard.Web/Core/Common/Handlers/IdentityPartHandler.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
|
||||
namespace Orchard.Core.Common.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class IdentityPartHandler : ContentHandler {
|
||||
public IdentityPartHandler(IRepository<IdentityPartRecord> identityRepository) {
|
||||
Filters.Add(StorageFilter.For(identityRepository));
|
||||
OnInitializing<IdentityPart>(AssignIdentity);
|
||||
}
|
||||
|
||||
protected void AssignIdentity(InitializingContentContext context, IdentityPart part) {
|
||||
part.Identifier = Guid.NewGuid().ToString("n");
|
||||
}
|
||||
|
||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||
var part = context.ContentItem.As<IdentityPart>();
|
||||
|
||||
if (part != null) {
|
||||
context.Metadata.Identity.Add("Identifier", part.Identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -36,5 +36,16 @@ namespace Orchard.Core.Common {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
SchemaBuilder.CreateTable("IdentityPartRecord",
|
||||
table => table
|
||||
.ContentPartRecord()
|
||||
.Column<string>("Identifier", column => column.Unlimited())
|
||||
);
|
||||
ContentDefinitionManager.AlterPartDefinition("IdentityPart", builder => builder.Attachable());
|
||||
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
10
src/Orchard.Web/Core/Common/Models/IdentityPart.cs
Normal file
10
src/Orchard.Web/Core/Common/Models/IdentityPart.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Core.Common.Models {
|
||||
public class IdentityPart : ContentPart<IdentityPartRecord> {
|
||||
public string Identifier {
|
||||
get { return Record.Identifier; }
|
||||
set { Record.Identifier = value; }
|
||||
}
|
||||
}
|
||||
}
|
7
src/Orchard.Web/Core/Common/Models/IdentityPartRecord.cs
Normal file
7
src/Orchard.Web/Core/Common/Models/IdentityPartRecord.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Core.Common.Models {
|
||||
public class IdentityPartRecord : ContentPartRecord {
|
||||
public virtual string Identifier { get; set; }
|
||||
}
|
||||
}
|
@@ -61,7 +61,11 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Common\Drivers\IdentityPartDriver.cs" />
|
||||
<Compile Include="Common\Handlers\IdentityPartHandler.cs" />
|
||||
<Compile Include="Common\Models\CommonPartVersionRecord.cs" />
|
||||
<Compile Include="Common\Models\IdentityPartRecord.cs" />
|
||||
<Compile Include="Common\Models\IdentityPart.cs" />
|
||||
<Compile Include="Common\Services\XmlRpcHandler.cs" />
|
||||
<Compile Include="Containers\Controllers\ItemController.cs" />
|
||||
<Compile Include="Containers\Drivers\ContainablePartDriver.cs" />
|
||||
|
Reference in New Issue
Block a user