Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to display icon for CustomSettings #13613

Merged
merged 3 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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