// Umbraco.Code.MapAll -ContentTypeId -ParentTabContentTypes -ParentTabContentTypeNames private static void Map(PropertyGroupBasic <MemberPropertyTypeBasic> source, PropertyGroupDisplay <MemberPropertyTypeDisplay> target, MapperContext context) { if (source.Id > 0) { target.Id = source.Id; } target.Inherited = source.Inherited; target.Name = source.Name; target.SortOrder = source.SortOrder; target.Properties = context.MapEnumerable <MemberPropertyTypeBasic, MemberPropertyTypeDisplay>(source.Properties); }
// Umbraco.Code.MapAll -ContentTypeId -ParentTabContentTypes -ParentTabContentTypeNames private static void Map(PropertyGroupBasic <PropertyTypeBasic> source, PropertyGroupDisplay <PropertyTypeDisplay> target, MapperContext context) { target.Inherited = source.Inherited; if (source.Id > 0) { target.Id = source.Id; } target.Key = source.Key; target.Type = source.Type; target.Name = source.Name; target.Alias = source.Alias; target.SortOrder = source.SortOrder; target.Properties = context.MapEnumerable <PropertyTypeBasic, PropertyTypeDisplay>(source.Properties); }
public IEnumerable <PropertyGroupDisplay <TPropertyType> > Map(IContentTypeComposition source) { // deal with groups var groups = new List <PropertyGroupDisplay <TPropertyType> >(); // add groups local to this content type foreach (var propertyGroup in source.PropertyGroups) { var group = new PropertyGroupDisplay <TPropertyType> { Id = propertyGroup.Id, Key = propertyGroup.Key, Type = propertyGroup.Type, Name = propertyGroup.Name, Alias = propertyGroup.Alias, SortOrder = propertyGroup.SortOrder, Properties = MapProperties(propertyGroup.PropertyTypes, source, propertyGroup.Id, false), ContentTypeId = source.Id }; groups.Add(group); } // add groups inherited through composition var localGroupIds = groups.Select(x => x.Id).ToArray(); foreach (var propertyGroup in source.CompositionPropertyGroups) { // skip those that are local to this content type if (localGroupIds.Contains(propertyGroup.Id)) { continue; } // get the content type that defines this group var definingContentType = GetContentTypeForPropertyGroup(source, propertyGroup.Id); if (definingContentType == null) { throw new Exception("PropertyGroup with id=" + propertyGroup.Id + " was not found on any of the content type's compositions."); } var group = new PropertyGroupDisplay <TPropertyType> { Inherited = true, Id = propertyGroup.Id, Key = propertyGroup.Key, Type = propertyGroup.Type, Name = propertyGroup.Name, Alias = propertyGroup.Alias, SortOrder = propertyGroup.SortOrder, Properties = MapProperties(propertyGroup.PropertyTypes, definingContentType, propertyGroup.Id, true), ContentTypeId = definingContentType.Id, ParentTabContentTypes = new[] { definingContentType.Id }, ParentTabContentTypeNames = new[] { definingContentType.Name } }; groups.Add(group); } // deal with generic properties var genericProperties = new List <TPropertyType>(); // add generic properties local to this content type var entityGenericProperties = source.PropertyTypes.Where(x => x.PropertyGroupId == null); genericProperties.AddRange(MapProperties(entityGenericProperties, source, PropertyGroupBasic.GenericPropertiesGroupId, false)); // add generic properties inherited through compositions var localGenericPropertyIds = genericProperties.Select(x => x.Id).ToArray(); var compositionGenericProperties = source.CompositionPropertyTypes .Where(x => x.PropertyGroupId == null && // generic localGenericPropertyIds.Contains(x.Id) == false); // skip those that are local foreach (var compositionGenericProperty in compositionGenericProperties) { var definingContentType = GetContentTypeForPropertyType(source, compositionGenericProperty.Id); if (definingContentType == null) { throw new Exception("PropertyType with id=" + compositionGenericProperty.Id + " was not found on any of the content type's compositions."); } genericProperties.AddRange(MapProperties(new [] { compositionGenericProperty }, definingContentType, PropertyGroupBasic.GenericPropertiesGroupId, true)); } // if there are any generic properties, add the corresponding tab if (genericProperties.Any()) { var genericGroup = new PropertyGroupDisplay <TPropertyType> { Id = PropertyGroupBasic.GenericPropertiesGroupId, Name = "Generic properties", SortOrder = 999, Properties = genericProperties, ContentTypeId = source.Id }; groups.Add(genericGroup); } // handle locked properties var lockedPropertyAliases = new List <string>(); // add built-in member property aliases to list of aliases to be locked foreach (var propertyAlias in Constants.Conventions.Member.GetStandardPropertyTypeStubs().Keys) { lockedPropertyAliases.Add(propertyAlias); } // lock properties by aliases foreach (var property in groups.SelectMany(x => x.Properties)) { property.Locked = lockedPropertyAliases.Contains(property.Alias); } // now merge tabs based on alias // as for one name, we might have one local tab, plus some inherited tabs var groupsGroupsByAlias = groups.GroupBy(x => x.Alias).ToArray(); groups = new List <PropertyGroupDisplay <TPropertyType> >(); // start with a fresh list foreach (var groupsByAlias in groupsGroupsByAlias) { // single group, just use it if (groupsByAlias.Count() == 1) { groups.Add(groupsByAlias.First()); continue; } // multiple groups, merge var group = groupsByAlias.FirstOrDefault(x => x.Inherited == false) // try local ?? groupsByAlias.First(); // else pick one randomly groups.Add(group); // in case we use the local one, flag as inherited group.Inherited = true; // TODO Remove to allow changing sort order of the local one (and use the inherited group order below) // merge (and sort) properties var properties = groupsByAlias.SelectMany(x => x.Properties).OrderBy(x => x.SortOrder).ToArray(); group.Properties = properties; // collect parent group info var parentGroups = groupsByAlias.Where(x => x.ContentTypeId != source.Id).ToArray(); group.ParentTabContentTypes = parentGroups.SelectMany(x => x.ParentTabContentTypes).ToArray(); group.ParentTabContentTypeNames = parentGroups.SelectMany(x => x.ParentTabContentTypeNames).ToArray(); } return(groups.OrderBy(x => x.SortOrder)); }