-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathContentmentContentBlocks.cs
87 lines (66 loc) · 2.95 KB
/
ContentmentContentBlocks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using uSync.Core;
using uSync.Core.Dependency;
using uSync.Core.Mapping;
namespace uSync.Community.Contrib.Mappers
{
/// <summary>
/// value mapper for Contentment content blocks.
/// </summary>
public class ContentmentContentBlocks : SyncNestedJsonValueMapperBase, ISyncMapper
{
public ContentmentContentBlocks(IEntityService entityService, Lazy<SyncValueMapperCollection> mapperCollection, IContentTypeService contentTypeService, IDataTypeService dataTypeService)
: base(entityService, mapperCollection, contentTypeService, dataTypeService)
{ }
public override string Name => "Contentment content block mapper";
public override string[] Editors => new string[]
{
"Umbraco.Community.Contentment.ContentBlocks"
};
protected override string ProcessValues(JToken jsonValue, string editorAlias, Func<JObject, IContentType, JObject> GetPropertiesMethod)
{
if (jsonValue is JArray elements)
{
foreach (var item in elements.Cast<JObject>())
{
var itemValue = item.Value<JObject>("value");
if (itemValue == null) continue;
var doctype = GetDocTypeByKey(item, "elementType");
if (doctype == null) continue;
GetImportProperties(itemValue, doctype);
}
return JsonConvert.SerializeObject(elements);
}
return JsonConvert.SerializeObject(jsonValue);
}
public override IEnumerable<uSyncDependency> GetDependencies(object value, string editorAlias, DependencyFlags flags)
{
var stringValue = GetValueAs<string>(value);
if (stringValue.TryParseValidJsonString(out JArray elements) is false)
return Enumerable.Empty<uSyncDependency>();
if (elements == null || !elements.Any())
return Enumerable.Empty<uSyncDependency>();
var dependencies = new List<uSyncDependency>();
foreach(var item in elements.Cast<JObject>())
{
var itemValue = item.Value<JObject>("value");
if (itemValue == null) continue;
var doctype = GetDocTypeByKey(item, "elementType");
if (doctype == null) continue;
if (flags.HasFlag(DependencyFlags.IncludeDependencies))
{
var doctypeDependency = CreateDocTypeDependency(doctype.Alias, flags);
if (doctypeDependency != null) dependencies.Add(doctypeDependency);
}
dependencies.AddRange(GetPropertyDependencies(itemValue, doctype, flags));
}
return dependencies;
}
}
}