Copied to clipboard

Flag this post as spam?

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


  • james 37 posts 121 karma points c-trib
    Feb 12, 2020 @ 11:25
    james
    0

    Moving trees to another section

    Hello,

    In Umbraco 7 we could move a tree to another section by updating the trees.config file. In v8 it looks like trees are now tied to a specific section via the Tree attribute on the tree's controller.

    I was looking at moving a tree by implementing a custom tree controller which inherited from the tree controller I want to move. My plan was to then remove the original tree from the tree collection builder and add my new tree, however the tree collection builder doesn't have a remove method (other collection builders, e.g. the dashboard collection builder, do have a Remove method). Even if this did work, it feels like a complicated way of doing something which was a simple config change before.

    Are we now unable to move trees in Umbraco 8, or should I be looking at a different approach here?

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Dec 27, 2021 @ 19:01
    Bjarne Fyrstenborg
    0

    I know this question was for Umbraco 8, but in Umbraco 9.1+ it is possible to remove a tree node using a composer and the RemoveTreeController() method.

    public class TreeComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
             builder.Trees().RemoveTreeController<ContentBlueprintTreeController>();
        }
    }
    

    and then add a new tree controller inheriting ContentBlueprintTreeController, which is auto-registered because of the Tree attribute:

    [Authorize(Policy = AuthorizationPolicies.SectionAccessContent)]
    [Tree(Constants.Applications.Content, Constants.Trees.ContentBlueprints)]
    [PluginController(Constants.Web.Mvc.BackOfficeTreeArea)]
    [CoreTree]
    
    public class ContentTemplatesController : ContentBlueprintTreeController
    {
        public ContentTemplatesController(
            ILocalizedTextService localizedTextService,
            UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
            IMenuItemCollectionFactory menuItemCollectionFactory,
            IContentService contentService,
            IContentTypeService contentTypeService,
            IEntityService entityService,
            IEventAggregator eventAggregator) 
            : base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, 
                    contentService, contentTypeService, entityService, eventAggregator)
        {
    
        }
    
        protected override ActionResult<TreeNode> CreateRootNode(FormCollection queryStrings)
        {
            return base.CreateRootNode(queryStrings);
        }
    }
    

    I may also be possible to inject the tree using TreeNodesRenderingNotification: https://our.umbraco.com/Documentation/Extending/Section-Trees/trees#treenodesrenderingnotification and in v8 TreeNodesRendering event: https://our.umbraco.com/Documentation/Extending/Section-Trees/trees-v8#treenodesrendering

    Before Umbraco 9.1 you could use TreeNodesRendering (v8) and TreeNodesRenderingNotification (v9) to remove/hide a specific tree.

    I have also suggested Content Templates should be added to content tree as content editors also need to edit and delete these, but we don't want to grant them full accesss to settings section: https://github.com/umbraco/Umbraco-CMS/discussions/11743

    Maybe it should even be a granular permission per user group.

Please Sign in or register to post replies

Write your reply to:

Draft