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

Added support for virtual backoffice icons #12833

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/Umbraco.Web.BackOffice/Services/IconService.cs
Expand Up @@ -136,6 +136,9 @@ private IEnumerable<FileInfo> GetAllIconsFiles()
}
}

// Get icons from the web root file provider (both physical and virtual)
icons.UnionWith(GetIconsFiles(_webHostEnvironment.WebRootFileProvider, Constants.SystemDirectories.AppPlugins));

IDirectoryContents? iconFolder =
_webHostEnvironment.WebRootFileProvider.GetDirectoryContents(_globalSettings.IconsPath);

Expand All @@ -148,6 +151,63 @@ private IEnumerable<FileInfo> GetAllIconsFiles()
return icons;
}


/// <summary>
/// Finds all SVG icon files based on the specified <paramref name="fileProvider"/> and <paramref name="path"/>.
/// The method will find both physical and virtual (eg. from a Razor Class Library) icons.
/// </summary>
/// <param name="fileProvider">The file provider to be used.</param>
/// <param name="path">The sub path to start from - should probably always be <see cref="Constants.SystemDirectories.AppPlugins"/>.</param>
/// <returns>A collection of <see cref="FileInfo"/> representing the found SVG icon files.</returns>
private static IEnumerable<FileInfo> GetIconsFiles(IFileProvider fileProvider, string path)
{
// Iterate through all plugin folders, this is necessary because on Linux we'll get casing issues when
// we directly try to access {path}/{pluginDirectory.Name}/{Constants.SystemDirectories.PluginIcons}
foreach (IFileInfo pluginDirectory in fileProvider.GetDirectoryContents(path))
{
// Ideally there shouldn't be any files, but we'd better check to be sure
if (!pluginDirectory.IsDirectory)
{
continue;
}

// Iterate through the sub directories of each plugin folder
foreach (IFileInfo subDir1 in fileProvider.GetDirectoryContents($"{path}/{pluginDirectory.Name}"))
{
// Skip files again
if (!subDir1.IsDirectory)
{
continue;
}

// Iterate through second level sub directories
foreach (IFileInfo subDir2 in fileProvider.GetDirectoryContents($"{path}/{pluginDirectory.Name}/{subDir1.Name}"))
{
// Skip files again
if (!subDir2.IsDirectory)
{
continue;
}

// Does the directory match the plugin icons folder? (case insensitive for legacy support)
if (!$"/{subDir1.Name}/{subDir2.Name}".InvariantEquals(Constants.SystemDirectories.PluginIcons))
{
continue;
}

// Iterate though the files of the second level sub directory. This should be where the SVG files are located :D
foreach (IFileInfo file in fileProvider.GetDirectoryContents($"{path}/{pluginDirectory.Name}/{subDir1.Name}/{subDir2.Name}"))
{
if (file.Name.InvariantEndsWith(".svg"))
{
yield return new FileInfo(file.PhysicalPath);
}
}
}
}
}
}

private IReadOnlyDictionary<string, string>? GetIconDictionary() => _cache.GetCacheItem(
$"{typeof(IconService).FullName}.{nameof(GetIconDictionary)}",
() => GetAllIconsFiles()
Expand Down