UmbracoKeyValuePropertyEditor 14.3.0
dotnet add package UmbracoKeyValuePropertyEditor --version 14.3.0
NuGet\Install-Package UmbracoKeyValuePropertyEditor -Version 14.3.0
<PackageReference Include="UmbracoKeyValuePropertyEditor" Version="14.3.0" />
paket add UmbracoKeyValuePropertyEditor --version 14.3.0
#r "nuget: UmbracoKeyValuePropertyEditor, 14.3.0"
// Install UmbracoKeyValuePropertyEditor as a Cake Addin #addin nuget:?package=UmbracoKeyValuePropertyEditor&version=14.3.0 // Install UmbracoKeyValuePropertyEditor as a Cake Tool #tool nuget:?package=UmbracoKeyValuePropertyEditor&version=14.3.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, bool uniqueFilter, bool allowNull)
{
try
{
string[] usedUpLanguageCodes = Array.Empty<string>();
try
{
// Current node block
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);
}
// Parent node block
IPublishedContent parentNode = null;
if (int.TryParse(parentNodeIdOrGuid, out int parentNodeId) && parentNodeId > 0)
{
parentNode = _umbracoHelper.Content(parentNodeId);
}
else if (Guid.TryParse(parentNodeIdOrGuid, out Guid Key))
{
parentNode = _umbracoHelper.Content(Key);
}
usedUpLanguageCodes = GetValuesOfChildrensProperty(parentNode, propertyAlias, currentNode?.Id).ToArray();
}
catch { uniqueFilter = false; }
LanguageDTO[] languageList = null;
if (uniqueFilter)
{
languageList = (new LanguageApiWrapper(_localizationService)).AllLanguages.Where(c => !usedUpLanguageCodes.Contains(c.ISOCode.ToLowerInvariant())).ToArray();
}
else
{
languageList = (new LanguageApiWrapper(_localizationService)).AllLanguages.ToArray();
}
if (allowNull)
{
languageList = languageList.Prepend(new LanguageDTO { ISOCode = "", EnglishName = "" }).ToArray();
}
return languageList.ToDictionary(c => c.ISOCode.ToLowerInvariant(), c => "").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 | Versions 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. |
-
net8.0
- Umbraco.Cms.Api.Management (>= 14.2.0)
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. |
|
UmbracoLanguagePicker
... |
|
UmbracoCountryPicker
... |
|
UmbracoSingleKeyValuePicker
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
14.3.0 | 267 | 9/24/2024 |
14.2.0 | 86 | 9/24/2024 |
14.1.0 | 200 | 9/10/2024 |
14.0.0 | 130 | 6/5/2024 |
13.0.2 | 271 | 4/16/2024 |
13.0.1 | 115 | 4/16/2024 |
13.0.0 | 202 | 12/16/2023 |
12.0.0 | 327 | 7/1/2023 |
5.0.0 | 1,893 | 9/24/2022 |
4.0.0 | 869 | 9/24/2022 |
3.2.0 | 450 | 9/21/2022 |
3.1.1 | 422 | 9/21/2022 |
3.1.0 | 426 | 9/21/2022 |
3.0.0 | 417 | 9/21/2022 |
2.0.0 | 441 | 9/21/2022 |
1.0.0 | 470 | 7/16/2022 |