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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

v14: Refactor settings arrays to ISet<T> (to ensure unique values and make them easily mutable) #16058

Open
wants to merge 1 commit into
base: v14/dev
Choose a base branch
from

Conversation

ronaldbarendse
Copy link
Contributor

Prerequisites

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

Description

Most configuration/options classes currently bind certain settings to arrays, which is mostly fine when configuring them from the appsettings.json files, but make adding new or removing default items in code a lot harder.

Consider removing TIFF and adding PBM and TGA image file types on the ContentImagingSettings configuration. Even when using the spread element .. to make adding items to the array easier, removing an existing item requires filtering the existing array:

using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;

public class ImageFileTypesComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
        => builder.Services.Configure<ContentImagingSettings>(options =>
        {
            options.ImageFileTypes =
            [
                // Remove TIFF
                ..options.ImageFileTypes.Where(x => x == "tiff"),
                // Add PBM and TGA
                "pbm",
                "tga"
            ];
        });
}

With this PR applied, the ImageFileTypes is now an ISet<string>, which can easily be mutated:

using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;

public class ImageFileTypesComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
        => builder.Services.Configure<ContentImagingSettings>(options =>
        {
            // Remove TIFF
            options.ImageFileTypes.Remove("tiff");

            // Add PBM and TGA
            options.ImageFileTypes.Add("pbm");
            options.ImageFileTypes.Add("tga");
        });
}

As a bonus, this won't add duplicate items to the set 馃檶馃徎 Additional improvements can be made by refactoring some settings to dictionaries, so they can be configured by unique key (e.g. RTE commands by alias, which would fix issue #14405). Other settings might benefit from being refactored as well, like the reserved paths and URLs (which would fix issue #12965).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant