如何在自定义字段类型中获取当前字段名称

时间:2012-05-16 05:00:38

标签: inheritance sitecore sitecore6

我正在尝试在我正在构建的自定义Sitecore字段上检索当前字段名称。换句话说,如果我的自定义字段类型应用于名为“元标题”的字段,我需要能够检索该名称。

This tutorial意味着您所要做的就是创建一个名为FieldName的公共自动属性,其余的是历史记录......遗憾的是,它似乎不起作用(FieldName始终为null或为空)。

有什么想法吗?我尝试从Sitecore.Web.UI.HtmlControls.ControlSitecore.Shell.Applications.ContentEditor.Text继承而没有运气。

1 个答案:

答案 0 :(得分:2)

您应该可以通过创建FieldID属性来访问控件中的字段ID。这应该等于定义字段的Template Field项的ID。因此,您可以通过

获取该字段的名称
var fieldItem = Sitecore.Context.ContentDatabase.GetItem(this.FieldID);
var fieldName = fieldItem.Name;

Sitecore可能在您的控件上设置的完整属性列表可在Sitecore.Shell.Applications.ContentEditor.EditorFormatter.SetProperties中找到。

ReflectionUtil.SetProperty(editor, "ID", field.ControlID);
ReflectionUtil.SetProperty(editor, "ItemID", field.ItemField.Item.ID.ToString());
ReflectionUtil.SetProperty(editor, "ItemVersion", field.ItemField.Item.Version.ToString());
ReflectionUtil.SetProperty(editor, "ItemLanguage", field.ItemField.Item.Language.ToString());
ReflectionUtil.SetProperty(editor, "FieldID", field.ItemField.ID.ToString());
ReflectionUtil.SetProperty(editor, "Source", field.ItemField.Source);
ReflectionUtil.SetProperty(editor, "ReadOnly", readOnly);
ReflectionUtil.SetProperty(editor, "Disabled", readOnly);
相关问题