using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Trees;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.BackOffice.Trees;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Cms.Web.Common.ModelBinders;
using Umbraco.Extensions;
public HousingInformationTreeController(ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory ?? throw new ArgumentNullException(nameof(menuItemCollectionFactory));
}
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var nodes = new TreeNodeCollection();
// check if we're rendering the root node's children
if (id == Constants.System.Root.ToInvariantString())
{
// you can get your custom nodes from anywhere, and they can represent anything...
Dictionary<int, string> blockMenuItems = new Dictionary<int, string>();
blockMenuItems.Add(1, "Block Information");
blockMenuItems.Add(2, "Block schedule");
// loop through our favourite things and create a tree item for each one
foreach (var mnuItem in blockMenuItems)
{
// add each node to the tree collection using the base CreateTreeNode method
// it has several overloads, using here unique Id of tree item,
// -1 is the Id of the parent node to create, eg the root of this tree is -1 by convention
// - the querystring collection passed into this route
// - the name of the tree node
// - css class of icon to display for the node
// - and whether the item has child nodes
var node = CreateTreeNode(mnuItem.Key.ToString(), "-1", queryStrings, mnuItem.Value, "icon-presentation", false);
nodes.Add(node);
}
}
return nodes;
}
protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
{
// create a Menu Item Collection to return so people can interact with the nodes in your tree
//var menu = _menuItemCollectionFactory.Create();
//if (id == Constants.System.Root.ToInvariantString())
//{
// // root actions, perhaps users can create new items in this tree, or perhaps it's not a content tree, it might be a read only tree, or each node item might represent something entirely different...
// // add your menu item actions or custom ActionMenuItems
// menu.Items.Add(new CreateChildEntity(LocalizedTextService));
// // add refresh menu item (note no dialog)
// menu.Items.Add(new RefreshNode(LocalizedTextService, true));
//}
//else
//{
// // add a delete action to each individual item
// menu.Items.Add<ActionDelete>(LocalizedTextService, true, opensDialog: true);
//}
return null;
}
protected override ActionResult<TreeNode?> CreateRootNode(FormCollection queryStrings)
{
var rootResult = base.CreateRootNode(queryStrings);
if (!(rootResult.Result is null))
{
return rootResult;
}
var root = rootResult.Value;
root.RoutePath = string.Format("{0}/{1}/{2}", Constants.Applications.Settings, "housinginformation", "overview");
// set the icon
root.Icon = "icon-hearts";
// could be set to false for a custom tree with a single node.
root.HasChildren = false;
//url for menu
root.MenuUrl = null;
return root;
}
}
}
I want to add custom menus for Block Information and Block schedule they both seems to want to call the edit.html in the back office section of the plugin.
I like it to do some thing like
/backoffice/Blocks
And
/backoffice/ BlockSchedual
Ect for other menu items I add.
Also I am finding when I click on "Block Information (Housing estate Information)" menu I am getting the settings menu and not the one I defined in code I have to click on it twice to get the correct menu.
If any one can point me in the direction of a tutorial that would be good. It need to be for version 13.
Umbraco 13 New Section and Tree
Hi,
I am looking for a tutorial that will show me how to add a new section and tree, I been working through the example in the docs:
https://docs.umbraco.com/umbraco-cms/v/13.latest-lts/extending/section-trees/sections
And
https://docs.umbraco.com/umbraco-cms/v/13.latest-lts/extending/section-trees/trees
But I hit a couple of issues:
Here is my Code:
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Actions; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models.Trees; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Trees; using Umbraco.Cms.Web.BackOffice.Trees; using Umbraco.Cms.Web.Common.Attributes; using Umbraco.Cms.Web.Common.ModelBinders; using Umbraco.Extensions;
namespace UmbracoCMS.App_Code.HousingInformation { [Tree("housinginformation", "housinginformation", TreeTitle = "Blocks", TreeGroup = "housinginformationGroup", SortOrder = 5)] [PluginController("HousingInformation")] public class HousingInformationTreeController : TreeController { private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
}
I want to add custom menus for Block Information and Block schedule they both seems to want to call the edit.html in the back office section of the plugin.
I like it to do some thing like
/backoffice/Blocks
And
/backoffice/ BlockSchedual
Ect for other menu items I add.
Also I am finding when I click on "Block Information (Housing estate Information)" menu I am getting the settings menu and not the one I defined in code I have to click on it twice to get the correct menu.
If any one can point me in the direction of a tutorial that would be good. It need to be for version 13.
Thanks in Advance. Darren
is working on a reply...