Files
Umbraco-CMS/src/Umbraco.Core/Trees/Tree.cs

71 lines
2.4 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics;
using Umbraco.Core.Services;
namespace Umbraco.Web.Trees
{
2019-01-22 17:23:30 +01:00
[DebuggerDisplay("Tree - {SectionAlias}/{TreeAlias}")]
2019-01-17 17:33:38 +11:00
public class Tree : ITree
{
2019-01-22 17:23:30 +01:00
public Tree(int sortOrder, string applicationAlias, string group, string alias, string title, TreeUse use, Type treeControllerType, bool isSingleNodeTree)
{
SortOrder = sortOrder;
2019-02-14 11:01:34 +11:00
SectionAlias = applicationAlias ?? throw new ArgumentNullException(nameof(applicationAlias));
2019-01-22 09:31:47 +01:00
TreeGroup = group;
2019-02-14 11:01:34 +11:00
TreeAlias = alias ?? throw new ArgumentNullException(nameof(alias));
2019-02-14 11:15:43 +11:00
TreeTitle = title;
2019-01-22 17:23:30 +01:00
TreeUse = use;
2019-02-14 11:01:34 +11:00
TreeControllerType = treeControllerType ?? throw new ArgumentNullException(nameof(treeControllerType));
IsSingleNodeTree = isSingleNodeTree;
}
2019-01-22 09:31:47 +01:00
/// <inheritdoc />
public int SortOrder { get; set; }
2019-01-22 09:31:47 +01:00
/// <inheritdoc />
public string SectionAlias { get; set; }
/// <inheritdoc />
public string TreeGroup { get; }
/// <inheritdoc />
public string TreeAlias { get; }
/// <inheritdoc />
public string TreeTitle { get; set; }
2019-01-22 17:23:30 +01:00
/// <inheritdoc />
public TreeUse TreeUse { get; set; }
2019-01-22 09:31:47 +01:00
/// <inheritdoc />
public bool IsSingleNodeTree { get; }
2019-01-22 09:31:47 +01:00
/// <summary>
/// Gets the tree controller type.
/// </summary>
public Type TreeControllerType { get; }
public static string GetRootNodeDisplayName(ITree tree, ILocalizedTextService textService)
{
var label = $"[{tree.TreeAlias}]";
// try to look up a the localized tree header matching the tree alias
var localizedLabel = textService.Localize("treeHeaders/" + tree.TreeAlias);
// if the localizedLabel returns [alias] then return the title if it's defined
if (localizedLabel != null && localizedLabel.Equals(label, StringComparison.InvariantCultureIgnoreCase))
{
if (string.IsNullOrEmpty(tree.TreeTitle) == false)
label = tree.TreeTitle;
}
else
{
// the localizedLabel translated into something that's not just [alias], so use the translation
label = localizedLabel;
}
return label;
}
}
}