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

Conversation

abjerner
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

Description

I was playing around with a new package I'm developing as a Razor Class Library, and noticed that my icon wasn't being picked up by Umbraco. I had a look through the IconService class, and realized it's only finding physical icons relative to the content root.

On the other hand, translations from virtual language files work fine, so after digging a bit around in the source code, I found the UmbracoBuilder.LocalizedText class, which I've used for inspiration for this PR.

My changes introduce a new GetIconsFiles method, which takes an IFileProvider and a string path as it's parameters, and then finds the SVG icon based on those two values. With this method, I could than add the following line to the existing GetAllIconFiles method to find physical and virtual icons relative to the web root:

icons.UnionWith(GetIconsFiles(_webHostEnvironment.WebRootFileProvider, Constants.SystemDirectories.AppPlugins));

The GetAllIconFiles method already handles physical icons relative to the content root. It doesn't support virtual files, so lines 108 to 137 could be replaced by the following line:

icons.UnionWith(GetIconsFiles(_webHostEnvironment.ContentRootFileProvider, Constants.SystemDirectories.AppPlugins));

I'm however not sure that RCL packages can have virtual files in the content root, which is why I did go along and replace the lines.


The implementation of the GetIconsFiles method is case insensitive, so it should match both BackOffice and backoffice - as well as .svg and .SVG. Although virtual icons hasn't been supported before, this should allow for people to stick with the deprecated BackOffice.


Testing may be bit difficult, as it requires adding a RCL-based NuGet package that contains a virtual icon. The file below can however be used for testing this:

Limbo.Umbraco.Twitter.1.0.0-alpha001-build202208131106.nupkg.zip

It's my still-very-much-in-development package. The file is really just a .nupkg, but GitHub wouldn't let me upload it I didn't add the .zip extension - so remember to rename it. When testing, I installed it as a local NuGet package in the Umbraco.Web.UI project.

Then the icon-limbo-twitter icon should then be available via Umbraco's icon picker (eg. when creating a new document type):

image

@github-actions
Copy link

github-actions bot commented Aug 13, 2022

Hi there @abjerner, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@nul800sebastiaan
Copy link
Member

Thanks very much @abjerner for providing a simple test case! We evaluated this one on UmbraCollab yesterday (https://youtu.be/pgelblKf7G8?t=501 somewhere after 15/20 minutes I believe) and ended up simplifying the code a lot. Until I read it again this morning and realized that wouldn't work for Linux, tested on Linux, didn't work, so now sadly we need to iterate all those directories indeed.

Anyway, the other comment is that we have InvarientEquals and InvariantEndsWith extension methods, which I replace here for you.

And finally, we're not sure what UnionWith does, but ideally it should actually overwrite an existing icon from Umbraco, that's what we do everywhere else. That was you could ship with custom icons that are "better"(?) than our icons. I believe UnionWith only adds items if they don't exist, but doesn't overwrite anything.

I think this PR is perfectly fine as it is, but it would be good to fix up that overwrite at some point!

Thanks again, this one will be part of the upcoming 10.3.0! 🎉

@abjerner
Copy link
Contributor Author

Great to see this merged 👍

I was about to check on it since I didn't recall seeing any activity (somehow missed the notification).

The use of UnionWith also puzzled me a bit. IIRC correctly I based this on another part of Umbraco that read from RCL virtual files. It seemed to work fine to the extent that I tested my PR, so I went with UnionWith as well.

I know about InvariantEquals and InvariantEndsWith. I can't remember why I didn't use those 🤷‍♂️

@abjerner abjerner deleted the v10/feature/virtual-backoffice-icons branch September 15, 2022 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants