Skip to content

Commit

Permalink
Make all template field info fields available so custom fields are al…
Browse files Browse the repository at this point in the history
…so accessible.
  • Loading branch information
jbreuer committed Aug 27, 2019
1 parent 745c255 commit 0cc50bc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Leprechaun/Model/TemplateFieldCodeGenerationMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Leprechaun.Model
Expand Down Expand Up @@ -32,6 +33,8 @@ public TemplateFieldCodeGenerationMetadata(TemplateFieldInfo field, string codeN

public virtual int SortOrder => Field.SortOrder;

public virtual Dictionary<Guid, string> AllFields => Field.AllFields;

/// <summary>
/// A unique name for this template field, usable as a C# identifier (e.g. property name)
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Leprechaun/Model/TemplateFieldInfo.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Leprechaun.Model
{
[DebuggerDisplay("{Path} ({Id})")]
public class TemplateFieldInfo
{
public TemplateFieldInfo()
{
AllFields = new Dictionary<Guid, string>();
}

public Guid Id { get; set; }

public string Name { get; set; }
Expand All @@ -23,5 +29,7 @@ public class TemplateFieldInfo
public string Section { get; set; }

public int SortOrder { get; set; }

public Dictionary<Guid, string> AllFields { get; set; }
}
}
40 changes: 39 additions & 1 deletion src/Leprechaun/TemplateReaders/DataStoreTemplateReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ protected virtual TemplateFieldInfo[] ParseTemplateFields(IItemData templateItem
Section = section.Name,
SortOrder = GetFieldValueAsInt(field, SortOrderFieldId, 100),
Source = GetFieldValue(field, SourceFieldId, string.Empty),
Type = GetFieldValue(field, FieldTypeFieldId, string.Empty)
Type = GetFieldValue(field, FieldTypeFieldId, string.Empty),
AllFields = GetAllFields(field)
});
}
}
Expand Down Expand Up @@ -180,5 +181,42 @@ protected virtual Guid[] ParseMultilistValue(string value)
}

protected virtual ICollection<Guid> IgnoredBaseTemplateIds => new HashSet<Guid> { TemplateIDs.StandardTemplate.Guid, TemplateIDs.Folder.Guid };

protected virtual Dictionary<Guid, string> GetAllFields(IItemData item)
{
var allFields = new Dictionary<Guid, string>();

foreach (var field in item.SharedFields)
{
if (!allFields.ContainsKey(field.FieldId))
{
allFields.Add(field.FieldId, field.Value);
}
}

foreach (var language in item.UnversionedFields)
{
foreach (var field in language.Fields)
{
if (!allFields.ContainsKey(field.FieldId))
{
allFields.Add(field.FieldId, field.Value);
}
}
}

foreach (var version in item.Versions)
{
foreach (var field in version.Fields)
{
if (!allFields.ContainsKey(field.FieldId))
{
allFields.Add(field.FieldId, field.Value);
}
}
}

return allFields;
}
}
}

0 comments on commit 0cc50bc

Please sign in to comment.