Skip to content

Commit 24f8c26

Browse files
Add property editor aliases to content artifacts
1 parent f895e5d commit 24f8c26

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

src/Umbraco.Deploy.Contrib.Export/ArtifactExportService.cs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using ICSharpCode.SharpZipLib.Zip;
6+
using Newtonsoft.Json;
7+
using Newtonsoft.Json.Linq;
58
using Umbraco.Core;
69
using Umbraco.Core.Deploy;
10+
using Umbraco.Core.Models;
711
using Umbraco.Deploy;
12+
using Umbraco.Deploy.Artifacts;
813
using Umbraco.Deploy.Files;
914

1015
namespace UmbracoDeploy.Contrib.Export
@@ -33,6 +38,7 @@ public static void ExportArtifacts(IEnumerable<IArtifact> artifacts, string zipA
3338
// Export to temp directory
3439
var exportPath = Path.Combine(Path.GetTempPath(), "Deploy", "export-" + Guid.NewGuid());
3540
DeployComponent.DiskEntityService.WriteArtifacts(exportPath, artifacts);
41+
AddPropertyEditorAliases(exportPath, artifacts.OfType<ContentArtifactBase>());
3642
DeployComponent.DiskEntityService.WriteFiles(exportPath, artifacts, fileTypes);
3743

3844
// Create export archive and delete temp directory
@@ -43,5 +49,64 @@ public static void ExportArtifacts(IEnumerable<IArtifact> artifacts, string zipA
4349
scope.Complete();
4450
}
4551
}
52+
53+
54+
private static void AddPropertyEditorAliases(string path, IEnumerable<ContentArtifactBase> artifacts)
55+
{
56+
var contentTypes = ApplicationContext.Current.Services.ContentTypeService.GetAllContentTypes();
57+
58+
foreach (var artifact in artifacts)
59+
{
60+
var filePath = Path.Combine(path, artifact.Udi.EntityType + "__" + artifact.Udi.Guid.ToString("n") + ".uda");
61+
62+
JObject json;
63+
using (var file = System.IO.File.OpenText(filePath))
64+
using (var reader = new JsonTextReader(file))
65+
{
66+
json = (JObject)JToken.ReadFrom(reader);
67+
}
68+
69+
json["PropertyEditorAliases"] = GetPropertyEditorAliases(contentTypes, artifact);
70+
71+
using (var file = System.IO.File.CreateText(filePath))
72+
using (var writer = new JsonTextWriter(file))
73+
{
74+
writer.Formatting = Formatting.Indented;
75+
76+
json.WriteTo(writer);
77+
}
78+
}
79+
}
80+
81+
private static JToken GetPropertyEditorAliases(IEnumerable<IContentType> contentTypes, ContentArtifactBase artifact)
82+
{
83+
var propertyEditorAliases = new Dictionary<string, string>();
84+
85+
foreach (var contentType in contentTypes)
86+
{
87+
string prefix;
88+
if (contentType.Key == artifact.ContentType.Guid)
89+
{
90+
// Add property editor aliases for the content type
91+
prefix = null;
92+
}
93+
else if (artifact.Dependencies.Any(x => x.Udi is GuidUdi guidUdi && guidUdi.EntityType == Constants.UdiEntityType.DocumentType && guidUdi.Guid == contentType.Key))
94+
{
95+
// Add prefixed property editor aliases for related content types (e.g. used by Nested Content)
96+
prefix = contentType.Alias + ".";
97+
}
98+
else
99+
{
100+
continue;
101+
}
102+
103+
foreach (var propertyType in contentType.CompositionPropertyTypes)
104+
{
105+
propertyEditorAliases[prefix + propertyType.Alias] = propertyType.PropertyEditorAlias;
106+
}
107+
}
108+
109+
return JToken.FromObject(propertyEditorAliases);
110+
}
46111
}
47112
}

0 commit comments

Comments
 (0)