コンテンツエディタでアイテムのツールチップを動的に変更する方法はありますか?必ずしもツールである必要はありません。フィールドのデフォルト値を示すために、フィールドのすぐ隣にあるアイテムとフィールドに基づいたテキストを出力しようとしています。これまでのところ、パイプラインプロセッサでは、フィールドプロパティを設定することはできません。これらはすべて読み取り専用です。どうすればそれにタグを付けることができるのか、またはその性質のものはありますか?
1102 次
1 に答える
10
はい、できますが、コンテンツエディターでフィールドレベルで使用できるSitecoreパイプラインが現在ないため、コンテンツエディターの個々のフィールドの外観を変更するには、少量のコードリフレクションが必要です。
- Sitecore.Shell.Applications.ContentEditor.EditorFormatterから継承するクラスMyEditorFormatterを作成します。
- ReflectorやDotPeekなどのツールを使用して、2つのメソッドの実装を元のEditorFormatterから新しいクラスにコピーします。
注: RenderLabelは、フィールドレベルのツールチップを書き込むメソッドですが、仮想ではないため、その機能をオーバーライドする唯一の方法は、それを呼び出すRenderFieldをオーバーライドすることです。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) {...}
- RenderFieldの署名を仮想からオーバーライドに変更します。これにより、args.EditorFormatter.RenderFieldが呼び出されて新しいコードが実行されます。
- 目的のツールチップロジックをRenderLabelに挿入します。
注:(カスタムテキスト)を新しいロジックに置き換えることができます。また、Description.Lengthのチェックを削除すると、説明が入力されていない場合に新しいツールチップが表示されなくなる可能性があることに注意してください。if (itemField.Description.Length > 0) { str4 = " title=\"" + itemField.Description + " (custom text)\""; }
パイプラインプロセッサを作成して、SitecoreのEditorFormatterを自分のものに置き換えます。
nullオブジェクトの例外を防ぐには、EditorFormatter.Argumentsを設定する必要があります。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; } } }
パイプラインプロセッサを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>
カスタムツールチップが表示されます。
更新: Mike Reynoldsは、このアプローチを使用して「このフィールドが定義されている場所」関数をコンテンツエディターに追加する方法を示す 非常に優れた記事を作成しました。
于 2013-02-09T16:15:33.687 に答える