I created a custom image field, so far its working fine. but when I take an image path and add it manually to the field without clicking browse. It disappears which is not the normal behavior in OOTB image field.
Custom Image Field Class:
public class CustomImage : Image
{
public string ItemID
{
get
{
return base.GetViewStateString("ItemID");
}
set
{
Assert.ArgumentNotNullOrEmpty(value, "ItemID");
base.SetViewStateString("ItemID", value);
}
}
public string FieldID
{
get
{
return base.GetViewStateString("FieldID");
}
set
{
Assert.ArgumentNotNullOrEmpty(value, "FieldID");
base.SetViewStateString("FieldID", value);
}
}
public override string Source
{
get
{
return this.GetViewStateString(nameof(Source));
}
set
{
Assert.ArgumentNotNull((object)value, nameof(value));
string str = MainUtil.UnmapPath(value);
if (str.EndsWith("/", StringComparison.InvariantCulture))
{
str = str.Substring(0, str.Length - 1);
}
else if (!string.IsNullOrWhiteSpace(value))
{
var item = Sitecore.Data.Database.GetDatabase("master").GetItem(new ID(ItemID));
str = Query(value, item);
}
this.SetViewStateString(nameof(Source), str);
}
}
public override void HandleMessage(Message message)
{
if (message["id"] != base.ID)
return;
if (message.Name.Equals("contentimage:customimage"))
{
Sitecore.Context.ClientPage.Start(this, "HandleCustomImage");
}
base.HandleMessage(message);
}
}
Does anyone knows how to solve this?
Thanks in advance.