4

コンテンツエディタでアイテムのツールチップを動的に変更する方法はありますか?必ずしもツールである必要はありません。フィールドのデフォルト値を示すために、フィールドのすぐ隣にあるアイテムとフィールドに基づいたテキストを出力しようとしています。これまでのところ、パイプラインプロセッサでは、フィールドプロパティを設定することはできません。これらはすべて読み取り専用です。どうすればそれにタグを付けることができるのか、またはその性質のものはありますか?

4

1 に答える 1

10

はい、できますが、コンテンツエディターでフィールドレベルで使用できるSitecoreパイプラインが現在ないため、コンテンツエディターの個々のフィールドの外観を変更するには、少量のコードリフレクションが必要です。

  1. Sitecore.Shell.Applications.ContentEditor.EditorFormatterから継承するクラスMyEditorFormatterを作成します。
  2. ReflectorやDotPeekなどのツールを使用して、2つのメソッドの実装を元のEditorFormatterから新しいクラスにコピーします。
    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)
    {...}
    注: RenderLabelは、フィールドレベルのツールチップを書き込むメソッドですが、仮想ではないため、その機能をオーバーライドする唯一の方法は、それを呼び出すRenderFieldをオーバーライドすることです。
  3. RenderFieldの署名を仮想からオーバーライドに変更します。これにより、args.EditorFormatter.RenderFieldが呼び出されて新しいコードが実行されます。
  4. 目的のツールチップロジックをRenderLabelに挿入します。
    if (itemField.Description.Length > 0)
    {
      str4 = " title=\"" + itemField.Description + " (custom text)\"";
    }
    注:(カスタムテキスト)を新しいロジックに置き換えることができます。また、Description.Lengthのチェックを削除すると、説明が入力されていない場合に新しいツールチップが表示されなくなる可能性があることに注意してください。
  5. パイプラインプロセッサを作成して、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;
        }
      }
    }
    
    nullオブジェクトの例外を防ぐには、EditorFormatter.Argumentsを設定する必要があります。

  6. パイプラインプロセッサを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 に答える