Skip to content

Commit

Permalink
Merge remote-tracking branch 'Stash/develop' into release/2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
majiccode committed Oct 30, 2019
2 parents 5b65081 + 8dd6f67 commit 9d48fa1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
8 changes: 7 additions & 1 deletion Sdl.Web.DXAResolver/Resolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,17 @@ private List<Component> GatherLinkedComponents(Component component)
}
}

HashSet<TcmUri> linkedComponents = new HashSet<TcmUri>();
foreach (var linkField in componentLinkFields)
{
if (linkField.Values != null)
{
components.AddRange(linkField.Values);
foreach (var c in linkField.Values)
{
if(linkedComponents.Contains(c.Id)) continue;
linkedComponents.Add(c.Id);
components.Add(c);
}
}
}
return components;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,16 @@ public DataModelBuilderPipeline(
ILogger logger = null
)
{
string[] typeNames = modelBuilderTypeNames.ToArray();
if (typeNames == null || typeNames.Length == 0)
throw new DxaException("No model builder type names specified.");

Session = renderedItem.ResolvedItem.Item.Session;
RenderedItem = renderedItem;
Settings = settings;
Logger = logger ?? new TemplatingLoggerAdapter(TemplatingLogger.GetLogger(GetType()));

foreach (string modelBuilderTypeName in modelBuilderTypeNames)
foreach (string modelBuilderTypeName in typeNames)
{
string qualifiedTypeName = modelBuilderTypeName.Contains(".") ? modelBuilderTypeName : $"Sdl.Web.Tridion.Templates.R2.Data.{modelBuilderTypeName}";
Type modelBuilderType = Type.GetType(qualifiedTypeName, throwOnError: true);
Expand Down
16 changes: 14 additions & 2 deletions Sdl.Web.Tridion.Templates.R2/Data/DefaultPageMetaModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void ExtractKeyValuePairs(XmlElement xmlElement, IDictionary<string, str
// New field
if (currentFieldName != null)
{
result.Add(currentFieldName, currentFieldValue);
AddValue(result, currentFieldName, currentFieldValue);
}
currentFieldName = childElement.Name;
currentFieldValue = fieldValue;
Expand All @@ -177,7 +177,19 @@ private void ExtractKeyValuePairs(XmlElement xmlElement, IDictionary<string, str

if (!string.IsNullOrEmpty(currentFieldValue))
{
result.Add(currentFieldName, currentFieldValue);
AddValue(result, currentFieldName, currentFieldValue);
}
}

private static void AddValue(IDictionary<string, string> result, string name, string value)
{
if (result.ContainsKey(name))
{
result[name] = $"{result[name]}, {value}";
}
else
{
result.Add(name, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public void BuildEntityModel(ref EntityModelData entityModelData, ComponentPrese
List<Condition> conditions = new List<Condition>();
foreach (var condition in cp.Conditions)
{
var mapped = MapConditions(condition.TargetGroup.Conditions);
if (mapped == null || mapped.Count <= 0) continue;
conditions.AddRange(mapped);
var mapped = MapTargetGroupCondition(condition);
if (mapped == null) continue;
conditions.Add(mapped);
}
if (conditions.Count > 0)
{
Expand Down
3 changes: 3 additions & 0 deletions Sdl.Web.Tridion.Templates.R2/Templates/GenerateEntityModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public override void Transform(Engine engine, Package package)
DataModelBuilderPipeline modelBuilderPipeline = new DataModelBuilderPipeline(renderedItem, settings, modelBuilderTypeNames);
EntityModelData entityModel = modelBuilderPipeline.CreateEntityModel(component, ct, includeComponentTemplateData);
OutputJson = JsonSerialize(entityModel, IsPreview, DataModelBinder.SerializerSettings);

if(string.IsNullOrEmpty(OutputJson))
throw new DxaException("Output Json is empty!");
}
catch (Exception ex)
{
Expand Down
2 changes: 2 additions & 0 deletions Sdl.Web.Tridion.Templates.R2/Templates/GeneratePageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public override void Transform(Engine engine, Package package)
DataModelBuilderPipeline modelBuilderPipeline = new DataModelBuilderPipeline(renderedItem, settings, modelBuilderTypeNames);
PageModelData pageModel = modelBuilderPipeline.CreatePageModel(page);
OutputJson = JsonSerialize(pageModel, IsPreview, DataModelBinder.SerializerSettings);
if (string.IsNullOrEmpty(OutputJson))
throw new DxaException("Output Json is empty!");
}
catch (Exception ex)
{
Expand Down
2 changes: 2 additions & 0 deletions Sdl.Web.Tridion.Templates/Common/TemplateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ protected void OutputSummary(string name, IEnumerable<string> files)
summaries.Add(summary);

string summariesJson = JsonSerialize(summaries, IsPreview);
if (string.IsNullOrEmpty(summariesJson))
throw new DxaException("Output Json should not be empty.");
outputItem = Package.CreateStringItem(ContentType.Text, summariesJson);
Package.PushItem(Package.OutputName, outputItem);
}
Expand Down

0 comments on commit 9d48fa1

Please sign in to comment.