2013-11-22 2 views
5

Sitecoreのコンテンツツリーは、一般的にグローバルおよびローカル(または国別)のページに分かれており、ブランチの顧客にサービスを提供します。ご存じのとおり、グローバルページは、地域のロケールに関係なく、当サイトのすべての視聴者に表示されますが、ローカライズ可能なグローバルページに特定のフィールドを実装しています。バナー広告、おすすめコンテンツなど許可が原因でSitecore multilistの選択項目の[アイテムが見つかりません]を抑制する方法はありますか?

マルチリストの場合、特定のコンテンツエディタは、アクセス権がある左側のアイテムのみを表示するようにセキュリティを設定しています。私たちが取り組んでいることは、他のブランチコンテンツエディタによって選択されたアイテムがマルチリストの右側の「選択された」エリアに現れていることです。アイテムを現在表示しているコンテンツエディタにそれらのパーミッションがない場合、それらは[Item not found]として表示されています。善意のコンテンツエディタが誤って削除したコンテンツエディタをダブルクリックすると、他の編集者が故意にそこに配置したコンテンツを削除していることに気付かずに削除されます。これは、私たちのドイツ語コンテンツの編集者の1のビューを使用して、どのように見えるかのスクリーンショットは以下の通りです:

Example of Item not found presentation

私は何を決定しようとしています抑えるために、セキュリティまたは他の方法を使用して、方法があるかどうです現在のコンテンツエディタに権限がないアイテムの[アイテムが見つかりません]というメッセージが表示されます。これを行う良い方法のヒント(それが可能な場合)は高く評価されます。

答えて

6

Sitecore.Shell.Applications.ContentEditor.MultilistExクラスを継承する独自のMultilistクラスを作成し、このクラスのDoRender()メソッドをオーバーライドすることができます。テキスト[Item Not Found]が表示されている場所で、項目が存在するが、ユーザーに(SecurityDisablerで項目を取得しようとして)アクセス権がないことを確認し、適切なメッセージを表示します。

次にあなたがcoreデータベースにアクセスし、自分のフィールドタイプを登録する必要があります

sitecore my multilist ex

そして最後に、新しく作成された型に、あなたのフィールドのタイプを切り替える - あなたのフィールドには、次のようになります。

sitecore custom multilist field result

は、以下のコードは、元の変更が必要なMultilistExコードを反映している:

using System.Collections; 
using System.Web.UI; 
using Sitecore; 
using Sitecore.Data.Items; 
using Sitecore.Diagnostics; 
using Sitecore.Globalization; 
using Sitecore.Resources; 
using Sitecore.SecurityModel; 

namespace My.Assembly.Namespace 
{ 
    public class MyMultilistEx : Sitecore.Shell.Applications.ContentEditor.MultilistEx 
    { 
     protected override void DoRender(HtmlTextWriter output) 
     { 
      Assert.ArgumentNotNull(output, "output"); 
      ArrayList selected; 
      IDictionary unselected; 
      GetSelectedItems(GetItems(Sitecore.Context.ContentDatabase.GetItem(ItemID)), out selected, out unselected); 
      ServerProperties["ID"] = ID; 
      string disabledMessage = string.Empty; 
      if (ReadOnly) 
       disabledMessage = " disabled=\"disabled\""; 
      output.Write("<input id=\"" + ID + "_Value\" type=\"hidden\" value=\"" + StringUtil.EscapeQuote(Value) + "\" />"); 
      output.Write("<table" + GetControlAttributes() + ">"); 
      output.Write("<tr>"); 
      output.Write("<td class=\"scContentControlMultilistCaption\" width=\"50%\">" + Translate.Text("All") + "</td>"); 
      output.Write("<td width=\"20\">" + Images.GetSpacer(20, 1) + "</td>"); 
      output.Write("<td class=\"scContentControlMultilistCaption\" width=\"50%\">" + Translate.Text("Selected") + "</td>"); 
      output.Write("<td width=\"20\">" + Images.GetSpacer(20, 1) + "</td>"); 
      output.Write("</tr>"); 
      output.Write("<tr>"); 
      output.Write("<td valign=\"top\" height=\"100%\">"); 
      output.Write("<select id=\"" + ID + "_unselected\" class=\"scContentControlMultilistBox\" multiple=\"multiple\" size=\"10\"" + disabledMessage + " ondblclick=\"javascript:scContent.multilistMoveRight('" + ID + "')\" onchange=\"javascript:document.getElementById('" + ID + "_all_help').innerHTML=selectedIndex>=0?options[selectedIndex].innerHTML:''\" >"); 
      foreach (DictionaryEntry dictionaryEntry in unselected) 
      { 
       Item unselectedItem = dictionaryEntry.Value as Item; 
       if (unselectedItem != null) 
        output.Write("<option value=\"" + GetItemValue(unselectedItem) + "\">" + unselectedItem.DisplayName + "</option>"); 
      } 
      output.Write("</select>"); 
      output.Write("</td>"); 
      output.Write("<td valign=\"top\">"); 
      RenderButton(output, "Core/16x16/arrow_blue_right.png", "javascript:scContent.multilistMoveRight('" + ID + "')"); 
      output.Write("<br />"); 
      RenderButton(output, "Core/16x16/arrow_blue_left.png", "javascript:scContent.multilistMoveLeft('" + ID + "')"); 
      output.Write("</td>"); 
      output.Write("<td valign=\"top\" height=\"100%\">"); 
      output.Write("<select id=\"" + ID + "_selected\" class=\"scContentControlMultilistBox\" multiple=\"multiple\" size=\"10\"" + disabledMessage + " ondblclick=\"javascript:scContent.multilistMoveLeft('" + ID + "')\" onchange=\"javascript:document.getElementById('" + ID + "_selected_help').innerHTML=selectedIndex>=0?options[selectedIndex].innerHTML:''\">"); 
      for (int index = 0; index < selected.Count; ++index) 
      { 
       Item selectedItem = selected[index] as Item; 
       if (selectedItem != null) 
       { 
        output.Write("<option value=\"" + GetItemValue(selectedItem) + "\">" + selectedItem.DisplayName + "</option>"); 
       } 
       else 
       { 
        string path = selected[index] as string; 
        if (path != null) 
        { 
         string optionDisabled = string.Empty; 
         Item linkedItem = Sitecore.Context.ContentDatabase.GetItem(path); 
         Item notAccessibleItem; 
         using (new SecurityDisabler()) 
         { 
          notAccessibleItem = Sitecore.Context.ContentDatabase.GetItem(path); 
         } 

         string text; 

         if (linkedItem == null && notAccessibleItem != null) 
         { 
          text = notAccessibleItem.DisplayName + " [You don't have access rights to this item]"; 
          optionDisabled = " disabled=\"disabled\""; 
         } 
         else 
         { 
          text = linkedItem == null 
               ? path + ' ' + Translate.Text("[Item not found]") 
               : linkedItem.DisplayName + ' ' + Translate.Text("[Not in the selection List]"); 
         } 
         output.Write("<option value=\"" + path + "\"" + optionDisabled + ">" + text + "</option>"); 
        } 
       } 
      } 
      output.Write("</select>"); 
      output.Write("</td>"); 
      output.Write("<td valign=\"top\">"); 
      RenderButton(output, "Core/16x16/arrow_blue_up.png", "javascript:scContent.multilistMoveUp('" + ID + "')"); 
      output.Write("<br />"); 
      RenderButton(output, "Core/16x16/arrow_blue_down.png", "javascript:scContent.multilistMoveDown('" + ID + "')"); 
      output.Write("</td>"); 
      output.Write("</tr>"); 
      output.Write("<tr>"); 
      output.Write("<td valign=\"top\">"); 
      output.Write("<div style=\"border:1px solid #999999;font:8pt tahoma;padding:2px;margin:4px 0px 4px 0px;height:14px\" id=\"" + ID + "_all_help\"></div>"); 
      output.Write("</td>"); 
      output.Write("<td></td>"); 
      output.Write("<td valign=\"top\">"); 
      output.Write("<div style=\"border:1px solid #999999;font:8pt tahoma;padding:2px;margin:4px 0px 4px 0px;height:14px\" id=\"" + ID + "_selected_help\"></div>"); 
      output.Write("</td>"); 
      output.Write("<td></td>"); 
      output.Write("</tr>"); 
      output.Write("</table>"); 
     } 

     private void RenderButton(HtmlTextWriter output, string icon, string click) 
     { 
      Assert.ArgumentNotNull(output, "output"); 
      Assert.ArgumentNotNull(icon, "icon"); 
      Assert.ArgumentNotNull(click, "click"); 
      ImageBuilder imageBuilder = new ImageBuilder(); 
      imageBuilder.Src = icon; 
      imageBuilder.Width = 16; 
      imageBuilder.Height = 16; 
      imageBuilder.Margin = "2px"; 
      if (!ReadOnly) 
       imageBuilder.OnClick = click; 
      output.Write((imageBuilder).ToString()); 
     } 

    } 
} 
+4

+1 _「善意のコンテンツエディタが誤って削除したコンテンツエディタをダブルクリックして削除しました」_オプションのユーザに

+0

@jammykam素晴らしいアイデア!回答が更新されました –

+0

これは素晴らしいオプションのようです - ありがとうございます。それはショットを与えるだろう! – wildwend

関連する問題