I have a custom field with two menu items, of which one of them opens a (sheer) dialog. But I need the value from other fields of the item in my dialog. However, I cannot find any reference to the original item. There is only some reference FIELD123456, which I cannot connect to an item or field.
Anyone a clue?
Edit:
This is the code of custom Field Type
using SC = Sitecore;
using SC_Diagnostics = Sitecore.Diagnostics;
using SC_Web = Sitecore.Web;
using SC_Shell_Applications_ContentEditor = Sitecore.Shell.Applications.ContentEditor;
namespace My.Feature.ImageCropper.FieldTypes
{
using System.Diagnostics.CodeAnalysis;
using System.Web.UI;
using System.Web.UI.WebControls;
[ExcludeFromCodeCoverage]
public class ImageCropperField : SC_Shell_Shell_Applications_ContentEditor.Text,
SC_Shell_Applications_ContentEditor.IContentField
{
protected override void Render(HtmlTextWriter output)
{
//cannot find any reference to item in base :-((
SC_Diagnostics.Assert.ArgumentNotNull(output, nameof(output));
base.Render(output);
}
public string GetValue() {return Value; }
public void SetValue(string value) { Value = value; }
public override void HandleMessage(SC_Web.UI.Sheer.Message message)
{
//cannot find any reference to item in this or message :-((
if (message["id"] != ID || string.IsNullOrWhiteSpace(message.Name))
return;
switch (message.Name)
{
case "imagecropper:cropImage":
SC.Context.ClientPage.Start(this, "CropImage");
return;
case "imagecropper:resetImage":
SC.Context.ClientPage.Start(this, "ResetImage");
return;
}
if (Value.Length > 0)
SetModified();
Value = string.Empty;
}
protected void CropImage(SC_Web.UI.Sheer.ClientPipelineArgs args)
{
//cannot find any reference to item in this or args :-((
if (args.IsPostBack)
{
if (args.HasResult && Value.Equals(args.Result) == false)
{
SetModified();
SetValue(args.Result);
}
}
else
{
//show popup
var url = SC.UIUtil.GetUri("control:ImageCropperDialog");
var value = GetValue();
if (!string.IsNullOrEmpty(value))
{
url = $"{url}&{value}";
}
SC_Web.UI.Sheer.SheerResponse.ShowModalDialog(url, "800", "600", "", true, "800", "600", false);
args.WaitForPostBack();
}
}
protected void ResetImage(SC_Web.UI.Sheer.ClientPipelineArgs args)
{
SetValue(string.Empty);
SetModified();
}
}
}
As you can see, the field inherits from Text and IContentField. All properties and methods are returning values to the control itself, the Home item (based on query string) or the Content Manager item in the core database (which is the context. I tried them all including:
this.GetContentItemFromQueryString()
this.GetContextItem();
this.GetItem();
this.GetItemFromQueryString();
this.TemplateControl.ID;
this.UniqueID;
The this.ItemId property is not present.
So.... is there another way to get the ID of the item where this field is used in?