2014-09-03 2 views
4

Я уверен, реализации динамического заполнителей в Sitecore 7, как описано в статьяхSitecore Dynamic PLACEHOLDERS Разрешенные Renderings

Он работает правильно так, что я могу добавить то же самое Рендеринг макета и рендеринга будет отображаться в соответствующем динамическом заполнителе. Однако, когда я нажимаю, чтобы добавить рендеринг к динамическому заполнителю, настройки placeholder не используются.

Ожидается, что с помощью разрешенных визуализаций, которые могут быть размещены на динамическом заполнителе, ожидается, что я ожидаю. Вместо этого дерево рендеринга/макета представлено вручную, чтобы предоставить рендеринговым редакторам контента возможность добавлять запрещенные визуализации к заполнителю.

Я отлаживал код и устанавливал правильный параметр «Заполнитель» для динамического заполнителя, и список разрешенных рендерингов извлекается, несмотря на то, что он установлен в аргументах, список не представлен для пользователя. См. Код ниже.

public class GetDynamicKeyAllowedRenderings : GetAllowedRenderings 
{ 
    //string that ends in a GUID 
    public const string DynamicKeyRegex = @"(.+){[\d\w]{8}\-([\d\w]{4}\-){3}[\d\w]{12}}"; 

    public new void Process(GetPlaceholderRenderingsArgs args) 
    { 
     Assert.IsNotNull(args, "args"); 

     // get the placeholder key 
     string placeholderKey = args.PlaceholderKey; 
     var regex = new Regex(DynamicKeyRegex); 
     Match match = regex.Match(placeholderKey); 

     // if the placeholder key text followed by a Guid 
     if (match.Success && match.Groups.Count > 0) 
     { 
      // Is a dynamic placeholder 
      placeholderKey = match.Groups[1].Value; 
     } 
     else 
     { 
      return; 
     } 

     Item placeholderItem = null; 
     if (ID.IsNullOrEmpty(args.DeviceId)) 
     { 
      placeholderItem = Client.Page.GetPlaceholderItem(placeholderKey, args.ContentDatabase, 
                  args.LayoutDefinition); 
     } 
     else 
     { 
      using (new DeviceSwitcher(args.DeviceId, args.ContentDatabase)) 
      { 
       placeholderItem = Client.Page.GetPlaceholderItem(placeholderKey, args.ContentDatabase, 
                   args.LayoutDefinition); 
      } 
     } 

     // Retrieve the allowed renderings for the Placeholder 
     List<Item> collection = null; 
     if (placeholderItem != null) 
     { 
      bool allowedControlsSpecified; 
      args.HasPlaceholderSettings = true; 
      collection = this.GetRenderings(placeholderItem, out allowedControlsSpecified); 
      if (allowedControlsSpecified) 
      { 
       args.CustomData["allowedControlsSpecified"] = true; 
      } 
     } 
     if (collection != null) 
     { 
      if (args.PlaceholderRenderings == null) 
      { 
       args.PlaceholderRenderings = new List<Item>(); 
      } 
      args.PlaceholderRenderings.AddRange(collection); 
     } 
    } 
} 

Поскольку этот код был разработан для Sitecore 6,5/6,6 Интересно, если в прыжке на Sitecore 7.0 принес изменения, которые влияют на вторую половину кода

ответ

6

Я нашел источник этой проблемы путем декомпиляции ядра Sitecore 7 и просмотра класса GetAllowedRenderings по умолчанию. Если «Допустимые визуализации» найдены, для параметра ShowTree необходимо установить значение «false». См. Ниже

public class GetDynamicKeyAllowedRenderings : GetAllowedRenderings 
    { 
     //string that ends in a GUID 
     public const string DynamicKeyRegex = @"(.+){[\d\w]{8}\-([\d\w]{4}\-){3}[\d\w]{12}}"; 

     public new void Process(GetPlaceholderRenderingsArgs args) 
     { 
      Assert.IsNotNull(args, "args"); 

      // get the placeholder key 
      string placeholderKey = args.PlaceholderKey; 
      var regex = new Regex(DynamicKeyRegex); 
      Match match = regex.Match(placeholderKey); 

      // if the placeholder key text followed by a Guid 
      if (match.Success && match.Groups.Count > 0) 
      { 
       // Is a dynamic placeholder 
       placeholderKey = match.Groups[1].Value; 
      } 
      else 
      { 
       return; 
      } 

      // Same as Sitecore.Pipelines.GetPlaceholderRenderings.GetAllowedRenderings from here but with fake placeholderKey 
      // i.e. the placeholder without the Guid 
      Item placeholderItem = null; 
      if (ID.IsNullOrEmpty(args.DeviceId)) 
      { 
       placeholderItem = Client.Page.GetPlaceholderItem(placeholderKey, args.ContentDatabase, 
                   args.LayoutDefinition); 
      } 
      else 
      { 
       using (new DeviceSwitcher(args.DeviceId, args.ContentDatabase)) 
       { 
        placeholderItem = Client.Page.GetPlaceholderItem(placeholderKey, args.ContentDatabase, 
                    args.LayoutDefinition); 
       } 
      } 

      List<Item> collection = null; 
      if (placeholderItem != null) 
      { 
       bool allowedControlsSpecified; 
       args.HasPlaceholderSettings = true; 
       collection = this.GetRenderings(placeholderItem, out allowedControlsSpecified); 
       if (allowedControlsSpecified) 
       { 
        // Hide the Layout/Rendering tree to show the Allowed Renderings 
        args.Options.ShowTree = false; 
       } 
      } 
      if (collection != null) 
      { 
       if (args.PlaceholderRenderings == null) 
       { 
        args.PlaceholderRenderings = new List<Item>(); 
       } 
       args.PlaceholderRenderings.AddRange(collection); 
      } 
     } 
    } 

Это изменение, внесенное Sitecore 7, похоже.

+0

Hey..nice work Jonathan. Можно ли выбрать первый разрешенный рендеринг и применить его к заполнителю без появления диалога «Выбрать рендеринг»? –

+0

Это хороший вопрос. Это должно быть возможно, но это может занять значительную часть работы. По существу, где я устанавливаю args.Options.ShowTree = false; вам нужно сделать звонок для разрешенных визуализаций. Затем декомпилируйте код Sitecore, чтобы узнать, что делает щелчок кнопки «Выбрать рендеринг», и скопировать его после вызова разрешенной визуализации. –

+0

Точно то, что я ищу сейчас .... это означает, что мне придется расширить реализацию sitecore в применении рендеринга. Любое руководство, где я могу найти этот код.? –

Смежные вопросы