diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs index 2ed765e57f..67104c10fc 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs @@ -9,15 +9,18 @@ using System.Web.UI; using System.Web.UI.WebControls; using Umbraco.Core; using Umbraco.Core.IO; +using Umbraco.Core.Models; using umbraco.BasePages; using umbraco.cms.businesslogic; -using umbraco.cms.businesslogic.media; -using umbraco.cms.businesslogic.property; using umbraco.cms.businesslogic.propertytype; using umbraco.cms.businesslogic.web; using umbraco.interfaces; using umbraco.uicontrols; using Content = umbraco.cms.businesslogic.Content; +using ContentType = umbraco.cms.businesslogic.ContentType; +using Media = umbraco.cms.businesslogic.media.Media; +using Property = umbraco.cms.businesslogic.property.Property; +using StylesheetProperty = umbraco.cms.businesslogic.web.StylesheetProperty; namespace umbraco.controls { @@ -111,7 +114,7 @@ namespace umbraco.controls Save += new EventHandler(standardSaveAndPublishHandler); _prntpage = (UmbracoEnsuredPage)Page; int i = 0; - var inTab = new Hashtable(); + Hashtable inTab = new Hashtable(); // zb-00036 #29889 : load it only once if (_virtualTabs == null) @@ -130,27 +133,14 @@ namespace umbraco.controls tabPage.Style.Add("text-align", "center"); - var tabId = tab.Id; - var propertyGroups = _contentType.ContentTypeItem.CompositionPropertyGroups.Where(x => x.Id == tabId || x.ParentId == tabId); - var propertyTypeAliases = propertyGroups.SelectMany(x => x.PropertyTypes.OrderBy(y => y.SortOrder).Select(y => new System.Tuple(y.Id, y.Alias, y.SortOrder))); - foreach (var items in propertyTypeAliases) + //Legacy vs New API loading of PropertyTypes + if (_contentType.ContentTypeItem != null) { - var property = _content.getProperty(items.Item2); - if (property != null) - { - AddControlNew(property, tabPage, tab.Caption); - - if (!inTab.ContainsKey(items.Item1.ToString(CultureInfo.InvariantCulture))) - inTab.Add(items.Item1.ToString(CultureInfo.InvariantCulture), true); - } - else - { - throw new ArgumentNullException( - string.Format( - "Property {0} ({1}) on Content Type {2} could not be retrieved for Document {3} on Tab Page {4}. To fix this problem, delete the property and recreate it.", - items.Item2, items.Item1, _content.ContentType.Alias, _content.Id, - tab.Caption)); - } + LoadPropertyTypes(_contentType.ContentTypeItem, tabPage, inTab, tab.Id, tab.Caption); + } + else + { + LoadPropertyTypes(tab, tabPage, inTab); } i++; @@ -173,6 +163,72 @@ namespace umbraco.controls } + /// + /// Loades PropertyTypes by Tab/PropertyGroup using the new API. + /// + /// + /// + /// + /// + /// + private void LoadPropertyTypes(IContentTypeComposition contentType, TabPage tabPage, Hashtable inTab, int tabId, string tabCaption) + { + var propertyGroups = contentType.CompositionPropertyGroups.Where(x => x.Id == tabId || x.ParentId == tabId); + var propertyTypeAliases = propertyGroups.SelectMany(x => x.PropertyTypes.OrderBy(y => y.SortOrder).Select(y => new Tuple(y.Id, y.Alias, y.SortOrder))); + foreach (var items in propertyTypeAliases) + { + var property = _content.getProperty(items.Item2); + if (property != null) + { + AddControlNew(property, tabPage, tabCaption); + + if (!inTab.ContainsKey(items.Item1.ToString(CultureInfo.InvariantCulture))) + inTab.Add(items.Item1.ToString(CultureInfo.InvariantCulture), true); + } + else + { + throw new ArgumentNullException( + string.Format( + "Property {0} ({1}) on Content Type {2} could not be retrieved for Document {3} on Tab Page {4}. To fix this problem, delete the property and recreate it.", + items.Item2, items.Item1, _content.ContentType.Alias, _content.Id, + tabCaption)); + } + } + } + + /// + /// Loades PropertyTypes by Tab using the Legacy API. + /// + /// + /// + /// + private void LoadPropertyTypes(ContentType.TabI tab, TabPage tabPage, Hashtable inTab) + { + // Iterate through the property types and add them to the tab + // zb-00036 #29889 : fix property types getter to get the right set of properties + // ge : had a bit of a corrupt db and got weird NRE errors so rewrote this to catch the error and rethrow with detail + var propertyTypes = tab.GetPropertyTypes(_content.ContentType.Id); + foreach (var propertyType in propertyTypes) + { + var property = _content.getProperty(propertyType); + if (property != null && tabPage != null) + { + AddControlNew(property, tabPage, tab.Caption); + + // adding this check, as we occasionally get an already in dictionary error, though not sure why + if (!inTab.ContainsKey(propertyType.Id.ToString(CultureInfo.InvariantCulture))) + inTab.Add(propertyType.Id.ToString(CultureInfo.InvariantCulture), true); + } + else + { + throw new ArgumentNullException( + string.Format( + "Property {0} ({1}) on Content Type {2} could not be retrieved for Document {3} on Tab Page {4}. To fix this problem, delete the property and recreate it.", + propertyType.Alias, propertyType.Id, _content.ContentType.Alias, _content.Id, tab.Caption)); + } + } + } + /// /// Initializes the control and ensures child controls are setup ///