Skip to content

Instantly share code, notes, and snippets.

@islaytitans
Created July 20, 2015 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save islaytitans/36e865e1bdd79d810d77 to your computer and use it in GitHub Desktop.
Save islaytitans/36e865e1bdd79d810d77 to your computer and use it in GitHub Desktop.
Hackathon - SitecoreFieldMapper
namespace DevToolKit.EntityMapping
{
public class SitecoreFieldMapper : ISitecoreFieldMapper
{
public FieldModel MapToEntity(Field field)
{
Assert.IsNotNull(field, "field can not be null");
var baseTemplate = TemplateManager.GetTemplate(
Sitecore.Configuration.Settings.DefaultBaseTemplate,
field.Database);
Assert.IsNotNull(baseTemplate, "template can not be null");
var template = field.GetTemplateField().Template;
var entity = new FieldModel
{
Id = field.ID.ToString(),
Name = field.Name,
Value = field.Value,
StandardValue = field.GetStandardValue(),
TemplateName = template.Name,
TemplateId = template.ID.ToString(),
StandardField = baseTemplate.ContainsField(field.ID),
SortOrder = field.Sortorder,
SectionSortOrder = field.SectionSortorder,
};
return entity;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment