Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Søren Kottal 530 posts 3521 karma points MVP 2x c-trib
    Aug 03, 2015 @ 19:36
    Søren Kottal
    1

    Order of "Child Items" tab when using listview

    Is it possible to alter the tab order, when using listviews?

    I would like to have the Child Items tab as the last tab before Generic Properties.

    Or maybe just hide it, and create a new tab with a custom listview property.

  • Mark Bowser 266 posts 852 karma points c-trib
    Aug 03, 2015 @ 20:56
    Mark Bowser
    100

    We have a couple of projects that we wanted to do this on as well. Unfortunately, I can't claim credit for getting this figured out. I just looked around in the source until I figured out how we did it. :)

    It looks like in the core of umbraco, umbraco uses AutoMapper to map the IContent into these ContentItemDisplay objects. We can use AutoMapper to intercept these mappings and make additional adjustments. In our case, we are rearranging the tabs.

    internal class TabMover
    {
        internal static void BindMappings()
        {
            Mapper.CreateMap<IContent, ContentItemDisplay>().AfterMap(HandleAfterMap);
        }
    
        internal static void HandleAfterMap(IContent content, ContentItemDisplay contentItem)
        {
            ReorderTabs(contentItem);
        }
    
        private static void ReorderTabs(ContentItemDisplay contentItem)
        {
            if (contentItem.Tabs.Any(t => t.Label == "Child items"))
            {
                var tabs = new List<Tab<ContentPropertyDisplay>>();
                tabs.AddRange(contentItem.Tabs);
    
                var list = tabs.OrderBy(x => (x.Label == "Child items" ? 2 : 1 )); 
    
                contentItem.Tabs = list;
            }
        }
    }
    

    Then you just make sure that on ApplicationStarted, we actually have the TabMover adjust the tab order.

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        base.ApplicationStarted(umbracoApplication, applicationContext);
    
        try
        {
            TabMover.BindMappings();
        }
        catch (Exception ex)
        {                
            Log.Error("BindMappings Failed", ex);
        }
    }
    
  • Søren Kottal 530 posts 3521 karma points MVP 2x c-trib
    Aug 04, 2015 @ 16:59
    Søren Kottal
    0

    Great, just saw your blog post.

    Heres some code for hiding the child items tab, if someone is interested.

    private static void RemoveChildItemsTab(ContentItemDisplay contentItem) { if (contentItem.Tabs.Any(t => t.Label == "Child items")) { var tabs = new List<>

            tabs.AddRange(contentItem.Tabs.Where(t => t.Label != "Child items"));
    
            contentItem.Tabs = tabs;
        }
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies