Reputation: 339
I am building a custom Field in sitecore 6.5. This field will generate new items based on the item in which the field resides (it uses the item's name to generate folders) and I need to reference the item in which the field is being used. How do I get access to this?
My custom field inherits from the sitecore Sitecore.Shell.Applications.ContentEditor.File class, if that helps at all.
My question is similar to the one located here: How to get a reference to the currently edited item when inside a custom field in Sitecore
However, the question there was for a previous version of sitecore, and the solutions no longer seem to work (ItemID is not in the viewstate, nor is it filled by the pipeline).
Thank you!
Upvotes: 2
Views: 2384
Reputation: 804
Struggling with the same problem for several hours, I ended up decompiling EditorFormatter and found that this class has Method called SetProperties.
By reflection (!?) this method checks if your field editor has the properties "ItemID", "ItemVersion", "ItemLanguage" .... sigh
Ok, so by adding a public property 'ItemID' we have the item being edited
Upvotes: 2
Reputation: 13141
If i'm not mistaken, Sitecore.Data.Fields.FileField
is a representation of the field's data in the Sitecore API. For instance, you would use it to retrieve the MediaItem
or Src
by casting an item's field like so:
var fieldSrc = ((FileField)Sitecore.Context.Item.Fields["My File Field"]).Src;
I don't think it's intended to be used as a custom field in the Sitecore client. Try inheriting from Sitecore.Shell.Applications.ContentEditor.File
or just strait up Sitecore.Web.UI.HtmlControls.Control
. As long as you have a public string ItemID { get; set; }
property defined, Sitecore should populate it with the current item ID.
Upvotes: 1