UmbracoKeyValuePropertyEditor 14.0.0

dotnet add package UmbracoKeyValuePropertyEditor --version 14.0.0
NuGet\Install-Package UmbracoKeyValuePropertyEditor -Version 14.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UmbracoKeyValuePropertyEditor" Version="14.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UmbracoKeyValuePropertyEditor --version 14.0.0
#r "nuget: UmbracoKeyValuePropertyEditor, 14.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UmbracoKeyValuePropertyEditor as a Cake Addin
#addin nuget:?package=UmbracoKeyValuePropertyEditor&version=14.0.0

// Install UmbracoKeyValuePropertyEditor as a Cake Tool
#tool nuget:?package=UmbracoKeyValuePropertyEditor&version=14.0.0

UmbracoKeyValuePropertyEditor

UmbracoKeyValuePropertyEditor property editor for Umbraco

This installs a custom property editor that can be used to configure external data to Umbraco nodes

After installing this, you can add inherit from KeyValueUmbracoPropertyEditorController to implement an api endpoint that can server as a data source, for example: to create the following API endpoint /umbraco/backoffice/Sample/LanguageDemoApi here is the sample code needed.

using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.Common;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Extensions;
using UmbracoKeyValuePropertyEditor;

namespace ExternalApiPickerDemo.Core.Demo
{

    [PluginController("UmbracoLanguagePicker")]
    public sealed class LanguageApiController : KeyValueUmbracoPropertyEditorController
    {
        private readonly UmbracoHelper _umbracoHelper;
        private readonly ILocalizationService _localizationService;

        public LanguageApiController(UmbracoHelper umbracoHelper, ILocalizationService localizationService)
        {
            _umbracoHelper = umbracoHelper;
            _localizationService = localizationService;
        }

        public override IOrderedEnumerable<KeyValuePair<string, string>> GetKeyValueList(string nodeIdOrGuid, string propertyAlias, int uniqueFilter = 0, int allowNull = 0)
        {
            try
            {
                string[] usedUpLanguageCodes = Array.Empty<string>();
                try
                {
                    IPublishedContent currentNode = null;
                    if (int.TryParse(nodeIdOrGuid, out int nodeId) && nodeId > 0)
                    {
                        currentNode = _umbracoHelper.Content(nodeId);
                    }
                    else if (Guid.TryParse(nodeIdOrGuid, out Guid Key))
                    {
                        currentNode = _umbracoHelper.Content(Key);
                    }

                    if (currentNode != null)
                    {
                        var parent = currentNode?.Parent;
                        if (parent == null)
                        {
                            usedUpLanguageCodes = GetValuesOfChildrensProperty(currentNode, propertyAlias, nodeId).ToArray();
                        }
                        else
                        {
                            usedUpLanguageCodes = GetValuesOfChildrensProperty(parent, propertyAlias, nodeId).Union(GetValuesOfChildrensProperty(currentNode, propertyAlias, nodeId)).ToArray();
                        }
                    }
                    else
                    {
                        usedUpLanguageCodes = GetValuesOfChildrensProperty(null, propertyAlias, nodeId).ToArray();
                    }
                }
                catch { uniqueFilter = 0; }
                LanguageDTO[] languageList = null;
                if (uniqueFilter == 1)
                {
                    languageList = (new LanguageApiWrapper(_localizationService)).AllLanguages.Where(c => !usedUpLanguageCodes.Contains(c.ISOCode.ToLowerInvariant())).ToArray();
                }
                else
                {
                    languageList = (new LanguageApiWrapper(_localizationService)).AllLanguages.ToArray();
                }
                if (allowNull == 1)
                {
                    languageList = languageList.Prepend(new LanguageDTO { ISOCode = "", EnglishName = "NONE" }).ToArray();
                }
                return languageList.ToDictionary(c => c.ISOCode.ToLowerInvariant(), c => c.EnglishName).OrderBy(v => v.Key);
            }
            catch
            {
                return null;
            }
        }

        private IEnumerable<string> GetValuesOfChildrensProperty(IPublishedContent node, string propertyAlias, int nodeId)
        {
            var nodes = node == null ? _umbracoHelper.ContentAtRoot() : node.Children;
            return nodes.Where(c => c.Id != nodeId).Select(c => c.Value<string>(propertyAlias)?.ToLowerInvariant());
        }
    }
}
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.Services;

namespace ExternalApiPickerDemo.Core.Demo
{
	public class LanguageApiWrapper
	{
		private readonly ILocalizationService _localizationService;

		public LanguageApiWrapper(ILocalizationService localizationService)
		{
			_localizationService = localizationService;
		}

		public IEnumerable<LanguageDTO> AllLanguages => _localizationService.GetAllLanguages().Select(l => new LanguageDTO() { ISOCode = l.IsoCode, EnglishName = l.CultureName });
	}
}
namespace ExternalApiPickerDemo.Core.Demo
{
	public class LanguageDTO
	{
		public string ISOCode { get; set; }
		public string EnglishName { get; set; }
	}
}

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on UmbracoKeyValuePropertyEditor:

Package Downloads
UmbracoMongoContactNumber

This package gives Umbraco editors to have the pleasure of using a property editor that is specific to phone numbers with their respective country phone codes etc, the database storing country phone code data is in MongoDB.

UmbracoCountryPicker

...

UmbracoSingleKeyValuePicker

Package Description

UmbracoLanguagePicker

...

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
14.0.0 75 6/5/2024
13.0.2 164 4/16/2024
13.0.1 78 4/16/2024
13.0.0 155 12/16/2023
12.0.0 260 7/1/2023
5.0.0 1,764 9/24/2022
4.0.0 807 9/24/2022
3.2.0 422 9/21/2022
3.1.1 394 9/21/2022
3.1.0 400 9/21/2022
3.0.0 405 9/21/2022
2.0.0 416 9/21/2022
1.0.0 437 7/16/2022