M.R*_*.R. 4 c# asp.net sitecore content-management-system sitecore6
有没有办法在内容编辑器中动态更改项目的工具提示?它不一定是toolip - 我只是想输出一个基于字段旁边的项目和字段的文本,以显示该字段的默认值.到目前为止,在流水线处理器中,没有一个字段属性可以设置 - 它们都是只读的.知道我怎么可能只是标记它,或者那种性质的东西?
Dan*_*vay 10
是的,它可以完成,但它确实需要少量的代码反射来修改内容编辑器中各个字段的外观,因为在字段级别当前没有可用于内容编辑器的Sitecore管道.
public virtual void RenderField(System.Web.UI.Control parent, Editor.Field field, bool readOnly)
{...}
public void RenderLabel(System.Web.UI.Control parent, Editor.Field field, Item fieldType, bool readOnly)
{...}
Run Code Online (Sandbox Code Playgroud) 注意: RenderLabel是写入字段级工具提示的方法,但由于它不是虚拟的,因此覆盖其功能的唯一方法是覆盖调用它的RenderField.if (itemField.Description.Length > 0)
{
str4 = " title=\"" + itemField.Description + " (custom text)\"";
}
Run Code Online (Sandbox Code Playgroud) 注意:您可以使用新逻辑替换(自定义文本).另请注意,您可能希望删除Description.Length上的检查,因为如果未填充描述,这将阻止您的新工具提示出现.创建一个管道处理器,用您的Sitecore替换Sitecore的EditorFormatter:
using Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor;
namespace CustomizedEditor
{
public class ChangeToMyEditorFormatter : RenderStandardContentEditor
{
public void Process(RenderContentEditorArgs args)
{
args.EditorFormatter = new MyEditorFormatter();
args.EditorFormatter.Arguments = args;
}
}
}
Run Code Online (Sandbox Code Playgroud) 填充EditorFormatter.Arguments是防止空对象异常所必需的. 将管道处理器添加到RenderContentEditor管道的开头:
<renderContentEditor>
<processor type="CustomizedEditor.ChangeToMyEditorFormatter, CustomizedEditor" />
<processor type="Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor, Sitecore.Client" />
<processor type="Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderStandardContentEditor, Sitecore.Client" />
</renderContentEditor>
Run Code Online (Sandbox Code Playgroud)您的自定义工具提示现在将显示:
更新: Mike Reynolds撰写了一篇非常好的文章,展示了如何使用此方法向内容编辑器添加"此字段定义位置"功能.