I was wondering if there is a way to remove an custom tree once it's already added. I found that you can remove a already added dashboard by doing this:
public void Compose(IUmbracoBuilder builder)
{
builder.Dashboards().Remove<Dashboard>();
}
So I was wondering if there is something similar you can do for a tree?
I tried using "Notifications". And it "kinda" works. The issue I am having is, when I try to add a child to a child. The children shows up on the same level instead of under each other. If I do it in a TreeController it works fine.
An idea I have is to simple use "Notifications" to add a css class to the already added tree and hide it. It works but it feels a bit janky.
public class TreeComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Trees().RemoveTreeController<DictionaryTreeController>();
}
}
I had no idea that this had been put into Umbraco core! 😆 I'm happy that I can remove that extension method from my Contentment package in a future release. 😁
Yeah, I have used it in a project to remove Content Templates tree from settings section and added it to content section instead.
Removing the core tree:
public class TreeComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
// Remove default Content Templates tree - this is added in content section in ContentTemplatesController.
builder.Trees().RemoveTreeController<ContentBlueprintTreeController>();
}
}
and then registering a custom tree inheriting from ContentBlueprintTreeController:
[Authorize(Policy = AuthorizationPolicies.SectionAccessContent)]
[Tree(Constants.Applications.Content, Constants.Trees.ContentBlueprints, SortOrder = 10)] //TreeGroup = Constants.Trees.Groups.Settings
[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)
{
var root = base.CreateRootNode(queryStrings);
if (!string.IsNullOrEmpty(root.Value.RoutePath))
{
// Update route to content section
root.Value.RoutePath = root.Value.RoutePath.Replace(Constants.Applications.Settings, Constants.Applications.Content);
}
return root;
}
protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
{
var collection = base.GetMenuForNode(id, queryStrings);
if (collection.Value.Items.Count > 0)
{
foreach (var menuItem in collection.Value.Items)
{
if (menuItem.Action is ActionCreateBlueprintFromContent)
{
var route = menuItem.AdditionalData["actionRoute"]?.ToString();
if (!string.IsNullOrEmpty(route))
{
// Update route to content section
menuItem.NavigateToRoute(route.Replace($"/{Constants.Applications.Settings}/", $"/{Constants.Applications.Content}/"));
}
}
}
}
return collection;
}
}
Remove an already added custom tree
Hi!
I was wondering if there is a way to remove an custom tree once it's already added. I found that you can remove a already added dashboard by doing this:
So I was wondering if there is something similar you can do for a tree?
I tried using "Notifications". And it "kinda" works. The issue I am having is, when I try to add a child to a child. The children shows up on the same level instead of under each other. If I do it in a TreeController it works fine.
An idea I have is to simple use "Notifications" to add a css class to the already added tree and hide it. It works but it feels a bit janky.
Any input is appreciated!
//Johannes
Hi Johannes,
While there isn't an official API to remove a tree, I do have code that uses Reflection to do it.
e.g. https://github.com/leekelleher/umbraco-contentment/blob/3.1.0/src/Umbraco.Community.Contentment/Core/Trees/TreeCollectionExtensions.cs#L17
With that extension method, you should be able to call it with the
.Trees()
method.e.g. https://github.com/leekelleher/umbraco-contentment/blob/3.1.0/src/Umbraco.Community.Contentment/Trees/CompositionExtensions.cs#L20
I hope this helps?
Cheers,
- Lee
Hi Johannes
Since v9.1.0 it has been possible to remove a tree using
RemoveTreeController
: https://github.com/umbraco/Umbraco-CMS/pull/11250I had no idea that this had been put into Umbraco core! 😆 I'm happy that I can remove that extension method from my Contentment package in a future release. 😁
Yeah, I have used it in a project to remove Content Templates tree from settings section and added it to content section instead.
Removing the core tree:
and then registering a custom tree inheriting from
ContentBlueprintTreeController
:Thank you so much Bjarne & Lee! You are life savers!
is working on a reply...