/// <summary>
        /// Maps properties on to the generic properties tab
        /// </summary>
        /// <param name="content"></param>
        /// <param name="tabs"></param>
        /// <param name="context"></param>
        /// <remarks>
        /// The generic properties tab is responsible for
        /// setting up the properties such as Created date, updated date, template selected, etc...
        /// </remarks>
        protected virtual void MapGenericProperties(IContentBase content, List <Tab <ContentPropertyDisplay> > tabs, MapperContext context)
        {
            // add the generic properties tab, for properties that don't belong to a tab
            // get the properties, map and translate them, then add the tab
            var noGroupProperties = content.GetNonGroupedProperties()
                                    .Where(x => IgnoreProperties.Contains(x.Alias) == false) // skip ignored
                                    .ToList();
            var genericProperties = MapProperties(content, noGroupProperties, context);

            var customProperties = GetCustomGenericProperties(content);

            if (customProperties != null)
            {
                genericProperties.AddRange(customProperties);
            }

            if (genericProperties.Count > 0)
            {
                tabs.Add(new Tab <ContentPropertyDisplay>
                {
                    Id         = 0,
                    Label      = LocalizedTextService.Localize("general", "properties"),
                    Alias      = "Generic properties",
                    Properties = genericProperties
                });
            }
        }
        /// <summary>
        /// Maps properties on to the generic properties tab
        /// </summary>
        /// <param name="content"></param>
        /// <param name="tabs"></param>
        /// <param name="context"></param>
        /// <remarks>
        /// The generic properties tab is responsible for
        /// setting up the properties such as Created date, updated date, template selected, etc...
        /// </remarks>
        protected virtual void MapGenericProperties(IContentBase content, List <Tab <ContentPropertyDisplay> > tabs, MapperContext context)
        {
            // add the generic properties tab, for properties that don't belong to a tab
            // get the properties, map and translate them, then add the tab
            var noGroupProperties = content.GetNonGroupedProperties()
                                    .Where(x => IgnoreProperties.Contains(x.Alias) == false) // skip ignored
                                    .ToList();
            var genericproperties = MapProperties(content, noGroupProperties, context);

            tabs.Add(new Tab <ContentPropertyDisplay>
            {
                Id         = 0,
                Label      = LocalizedTextService.Localize("general", "properties"),
                Alias      = "Generic properties",
                Properties = genericproperties,
                Type       = PropertyGroupType.Group.ToString()
            });

            var genericProps = tabs.Single(x => x.Id == 0);

            //store the current props to append to the newly inserted ones
            var currProps = genericProps.Properties.ToArray();

            var contentProps = new List <ContentPropertyDisplay>();

            var customProperties = GetCustomGenericProperties(content);

            if (customProperties != null)
            {
                //add the custom ones
                contentProps.AddRange(customProperties);
            }

            //now add the user props
            contentProps.AddRange(currProps);

            //re-assign
            genericProps.Properties = contentProps;

            //Show or hide properties tab based on whether it has or not any properties
            if (genericProps.Properties.Any() == false)
            {
                //loop through the tabs, remove the one with the id of zero and exit the loop
                for (var i = 0; i < tabs.Count; i++)
                {
                    if (tabs[i].Id != 0)
                    {
                        continue;
                    }
                    tabs.RemoveAt(i);
                    break;
                }
            }
        }
        protected override IEnumerable <Tab <ContentPropertyDisplay> > ResolveCore(IContentBase content)
        {
            var aggregateTabs = new List <Tab <ContentPropertyDisplay> >();

            //now we need to aggregate the tabs and properties since we might have duplicate tabs (based on aliases) because
            // of how content composition works.
            foreach (var propertyGroups in content.PropertyGroups.OrderBy(x => x.SortOrder).GroupBy(x => x.Name))
            {
                var aggregateProperties = new List <ContentPropertyDisplay>();

                //add the properties from each composite property group
                foreach (var current in propertyGroups)
                {
                    var propsForGroup = content.GetPropertiesForGroup(current)
                                        .Where(x => IgnoreProperties.Contains(x.Alias) == false); //don't include ignored props

                    aggregateProperties.AddRange(
                        Mapper.Map <IEnumerable <Property>, IEnumerable <ContentPropertyDisplay> >(
                            propsForGroup));
                }

                if (aggregateProperties.Count == 0)
                {
                    continue;
                }

                TranslateProperties(aggregateProperties);

                //then we'll just use the root group's data to make the composite tab
                var rootGroup = propertyGroups.First(x => x.ParentId == null);
                aggregateTabs.Add(new Tab <ContentPropertyDisplay>
                {
                    Id         = rootGroup.Id,
                    Alias      = rootGroup.Name,
                    Label      = TranslateItem(rootGroup.Name),
                    Properties = aggregateProperties,
                    IsActive   = false
                });
            }

            //now add the generic properties tab for any properties that don't belong to a tab
            var orphanProperties = content.GetNonGroupedProperties()
                                   .Where(x => IgnoreProperties.Contains(x.Alias) == false); //don't include ignored props

            //now add the generic properties tab
            var genericproperties = Mapper.Map <IEnumerable <Property>, IEnumerable <ContentPropertyDisplay> >(orphanProperties).ToList();

            TranslateProperties(genericproperties);

            aggregateTabs.Add(new Tab <ContentPropertyDisplay>
            {
                Id         = 0,
                Label      = ui.Text("general", "properties"),
                Alias      = "Generic properties",
                Properties = genericproperties
            });

            //set the first tab to active
            aggregateTabs.First().IsActive = true;

            return(aggregateTabs);
        }
示例#4
0
        protected override IEnumerable <Tab <ContentPropertyDisplay> > ResolveCore(IContentBase content)
        {
            var tabs = new List <Tab <ContentPropertyDisplay> >();

            // add the tabs, for properties that belong to a tab
            // need to aggregate the tabs, as content.PropertyGroups contains all the composition tabs,
            // and there might be duplicates (content does not work like contentType and there is no
            // content.CompositionPropertyGroups).
            var groupsGroupsByName = content.PropertyGroups.OrderBy(x => x.SortOrder).GroupBy(x => x.Name);

            foreach (var groupsByName in groupsGroupsByName)
            {
                var properties = new List <Property>();

                // merge properties for groups with the same name
                foreach (var group in groupsByName)
                {
                    var groupProperties = content.GetPropertiesForGroup(group)
                                          .Where(x => IgnoreProperties.Contains(x.Alias) == false); // skip ignored

                    properties.AddRange(groupProperties);
                }

                if (properties.Count == 0)
                {
                    continue;
                }

                // Sort properties so items from different compositions appear in correct order (see U4-9298). Map sorted properties.
                var mappedProperties = Mapper.Map <IEnumerable <Property>, IEnumerable <ContentPropertyDisplay> >(properties.OrderBy(prop => prop.PropertyType.SortOrder));

                TranslateProperties(mappedProperties);

                // add the tab
                // we need to pick an identifier... there is no "right" way...
                var g = groupsByName.FirstOrDefault(x => x.Id == content.ContentTypeId) // try local
                        ?? groupsByName.First();                                        // else pick one randomly
                var groupId   = g.Id;
                var groupName = groupsByName.Key;
                tabs.Add(new Tab <ContentPropertyDisplay>
                {
                    Id         = groupId,
                    Alias      = groupName,
                    Label      = _localizedTextService.UmbracoDictionaryTranslate(groupName),
                    Properties = mappedProperties,
                    IsActive   = false
                });
            }

            // add the generic properties tab, for properties that don't belong to a tab
            // get the properties, map and translate them, then add the tab
            var noGroupProperties = content.GetNonGroupedProperties()
                                    .Where(x => IgnoreProperties.Contains(x.Alias) == false); // skip ignored
            var genericproperties = Mapper.Map <IEnumerable <Property>, IEnumerable <ContentPropertyDisplay> >(noGroupProperties).ToList();

            TranslateProperties(genericproperties);

            tabs.Add(new Tab <ContentPropertyDisplay>
            {
                Id         = 0,
                Label      = _localizedTextService.Localize("general/properties"),
                Alias      = "Generic properties",
                Properties = genericproperties
            });

            // activate the first tab
            tabs.First().IsActive = true;

            return(tabs);
        }