Is there a way to change the tooltip of an item dynamically in the content editor? It doesn't necessarily have to be the toolip - I'm just trying to output a text that is based on the item and field right next to the field, to show what the default value of the field would be. So far, in the pipeline processor, none of the field properties can be set - they are all readonly. Any idea how maybe I can just tag onto it, or something of that nature?
Yes, it can be done, but it does require a small amount of code reflection to modify the appearance of individual fields in the Content Editor, since there is currently no Sitecore pipeline available for the Content Editor at a field level.
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)
{...}
Note: RenderLabel is the method that writes the field-level tooltip, but since it is not virtual, the only way to override its functionality is to override RenderField, which calls it. if (itemField.Description.Length > 0)
{
str4 = " title=\"" + itemField.Description + " (custom text)\"";
}
Note: You can replace (custom text) with your new logic. Also note that you may wish to remove the check on the Description.Length, as this will prevent your new tooltip from appearing if the Description is not populated.Create a pipeline processor to replace Sitecore's EditorFormatter with yours:
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;
}
}
}
Populating EditorFormatter.Arguments is necessary to prevent a null object exception. Add your pipeline processor to the start of the RenderContentEditor pipeline:
<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>
Your custom tooltip will now appear:
Update: Mike Reynolds has written a very nice article showing how this approach can be used to add a "Where is this field defined" function to the Content Editor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With