Feature Request: Organization of Container List on Containable Parts

Topics: Core
Sep 15, 2012 at 12:02 AM
Edited Sep 15, 2012 at 12:03 AM

I have made pages Containers and Containable, plus have quite a few custom Content Types that are also containers. This ends up creating quite a long list of visually unordered containers in the "Add to" dropdown.

I have edited the ContainablePartDriver to display them in alphabetical order based on title and to also indicate what the parent container is if it has one. I know this could be done better or in a more efficent way but I'm posting what I did quickly to get it accomplished for my needs.

 		 var listItems = new[] { new SelectListItem { Text = T("(None)").Text, Value = "0" } }
                        .Concat(containers.Select(x => new SelectListItem {
                            Value = Convert.ToString(x.Id),
                            Text = x.ContentItem.TypeDefinition.DisplayName + ": " + _contentManager.GetItemMetadata(x.ContentItem).DisplayText + ContainerDisplayText(x.ContentItem),
                            Selected = x.Id == model.ContainerId,
                    model.AvailableContainers = new SelectList(listItems.OrderBy(x => x.Text), "Value""Text", model.ContainerId);
        private IContent Container(IContent content)
            var commonPart = content.As<ICommonPart>();
            if (commonPart == null)
                return null;
            return commonPart.Container;
        private string ContainerDisplayText(IContent content)
            var container = Container(content);
            if (container == null)
                return string.Empty;
            return " (Child of: " + _contentManager.GetItemMetadata(container).DisplayText +")";
Sep 15, 2012 at 12:13 AM

Thanks. Quick comment: the return value of ContainerDisplayText is not localizable.

Sep 15, 2012 at 1:28 AM
Edited Sep 16, 2012 at 3:37 PM

Yes, I wasn't concerned about it for my implimentation but it should be done. I would also take it a little further to also show what the container TypeDefinition so it shows as:

Page: Documents (Child of Page: Project ABC)