Skip to content

Commit

Permalink
#139 make sure we serialize the settingsData too
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Aug 20, 2020
1 parent 1cdcdc9 commit 88aebd2
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions uSync8.ContentEdition/Mapping/Mappers/BlockListMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ namespace uSync8.ContentEdition.Mapping.Mappers
public class BlockListMapper : SyncNestedValueMapperBase, ISyncMapper
{
private readonly string docTypeKeyAlias = "contentTypeKey";
private readonly string[] contentBlocks = new string[]
{
"contentData", "settingsData"
};

public BlockListMapper(IEntityService entityService,
IContentTypeService contentTypeService,
Expand All @@ -43,22 +47,25 @@ public override string GetExportValue(object value, string editorAlias)
var jsonValue = GetJsonValue(value);
if (jsonValue == null) return value.ToString();

if (jsonValue.ContainsKey("contentData"))
foreach (var block in contentBlocks)
{
var contentData = jsonValue.Value<JArray>("contentData");
if (contentData == null) return value.ToString();

foreach (var item in contentData.Cast<JObject>())
if (jsonValue.ContainsKey(block))
{
var doctype = GetDocTypeByKey(item, docTypeKeyAlias);
if (doctype == null) continue;
var contentData = jsonValue.Value<JArray>(block);
if (contentData == null) return value.ToString();

GetExportProperties(item, doctype);
}
foreach (var item in contentData.Cast<JObject>())
{
var doctype = GetDocTypeByKey(item, docTypeKeyAlias);
if (doctype == null) continue;

GetExportProperties(item, doctype);
}

}
return JsonConvert.SerializeObject(jsonValue, Formatting.Indented);
}

return value.ToString();

}
Expand All @@ -74,19 +81,22 @@ public override IEnumerable<uSyncDependency> GetDependencies(object value, strin
// format of block data.
// { "layout" : {}, "contentData": {}, "settingsData": {} }

// contentData is the thing we need to inspect.
if (jsonValue.ContainsKey("contentData"))
foreach (var block in contentBlocks)
{
var contentData = jsonValue.Value<JArray>("contentData");
if (contentData != null)
// contentData is the thing we need to inspect.
if (jsonValue.ContainsKey(block))
{
foreach (var contentItem in contentData.Cast<JObject>())
var contentData = jsonValue.Value<JArray>(block);
if (contentData != null)
{
var contentType = GetDocTypeByKey(contentItem, "contentTypeKey");
if (contentType != null)
foreach (var contentItem in contentData.Cast<JObject>())
{
dependencies.AddNotNull(CreateDocTypeDependency(contentType, flags));
dependencies.AddRange(this.GetPropertyDependencies(contentItem, contentType, flags));
var contentType = GetDocTypeByKey(contentItem, this.docTypeKeyAlias);
if (contentType != null)
{
dependencies.AddNotNull(CreateDocTypeDependency(contentType, flags));
dependencies.AddRange(this.GetPropertyDependencies(contentItem, contentType, flags));
}
}
}
}
Expand Down

0 comments on commit 88aebd2

Please sign in to comment.