Skip to content

Commit

Permalink
Allow to display icon for CustomSettings (#13613)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored May 2, 2023
1 parent e7865c3 commit b2e6465
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
using OrchardCore.CustomSettings.Services;
using OrchardCore.Mvc.Utilities;
using OrchardCore.Navigation;

namespace OrchardCore.CustomSettings
Expand Down Expand Up @@ -33,6 +34,8 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
.Add(S["Settings"], settings => settings
.Add(new LocalizedString(type.DisplayName, type.DisplayName), type.DisplayName.PrefixPosition(), layers => layers
.Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = type.Name })
.AddClass(type.Name.HtmlClassify())
.Id(type.Name.HtmlClassify())
.Permission(Permissions.CreatePermissionForType(type))
.Resource(type.Name)
.LocalNav()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,6 @@ public static string Ellipsize(this string text, int characterCount, string elli
return trimmed + ellipsis;
}

public static string HtmlClassify(this string text)
{
if (string.IsNullOrWhiteSpace(text))
return "";

var friendlier = text.CamelFriendly();

var result = new char[friendlier.Length];

var cursor = 0;
var previousIsNotLetter = false;
for (var i = 0; i < friendlier.Length; i++)
{
char current = friendlier[i];
if (IsLetter(current) || (char.IsDigit(current) && cursor > 0))
{
if (previousIsNotLetter && i != 0 && cursor > 0)
{
result[cursor++] = '-';
}

result[cursor++] = char.ToLowerInvariant(current);
previousIsNotLetter = false;
}
else
{
previousIsNotLetter = true;
}
}

return new string(result, 0, cursor);
}

public static LocalizedString OrDefault(this string text, LocalizedString defaultValue)
{
return string.IsNullOrEmpty(text)
Expand Down

0 comments on commit b2e6465

Please sign in to comment.