I am storing cropping information on my Sitecore Media Library images in a field that was added to the /sitecore/templates/System/Media/Unversioned/Image
template.
I would like to access this field along with all of the other properties that exist in the Glass.Mapper.Sc.Fields.Image
complex field type so that I can continue to use GlassHtml.RenderImage()
in my views.
My initial attempts to inherit from the class were unsuccessful - it appears to break the mapping behavior - so I am wondering if there is another way to extend this class with additional properties?
Here's what I've tried:
[SitecoreType(AutoMap = true)]
public class MyImage : Glass.Mapper.Sc.Fields.Image
{
public virtual string CropInfo { get; set; }
}
You will need to implement a custom data handler to map the additional field.
I would create a data handler that inherits from the standard Image data handler:
https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/DataMappers/SitecoreFieldImageMapper.cs
Then customise
GetField
andSetField
.Once you have created the custom data handler you need to register it with the Windsor container. See tutorial 19 for how to do this:
http://glass.lu/docs/tutorial/sitecore/tutorial19/tutorial19.html
The important part: