Skip to content

Commit

Permalink
Setting default item type icon in configuration editor
Browse files Browse the repository at this point in the history
  • Loading branch information
callumbwhyte committed May 23, 2022
1 parent 096dc85 commit 85c27be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Umbraco.Cms.Core.IO;
using System.Collections.Generic;
using System.Linq;
using Our.Umbraco.Meganav.Models;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.PropertyEditors;

namespace Our.Umbraco.Meganav.PropertyEditors
Expand All @@ -10,5 +13,23 @@ public MeganavConfigurationEditor(IIOHelper ioHelper)
{

}

public override IDictionary<string, object> ToValueEditor(object configuration)
{
var value = base.ToValueEditor(configuration);

if (value.TryGetValue("itemTypes", out var data) == true)
{
if (data is IEnumerable<IMeganavItemType> itemTypes)
{
foreach (var itemType in itemTypes.OfType<MeganavItemType>())
{
itemType.Icon = itemType.Icon ?? "icon-link";
}
}
}

return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@
vm.$onInit = function () {
localizationHelper.translate(vm.labels);

vm.itemTypes.forEach(itemType => {
if (!itemType.icon) {
itemType.icon = "icon-link";
}
});

var setItemTypes = function (items) {
items.forEach(item => {
item.itemType = getItemType(item);
Expand Down

0 comments on commit 85c27be

Please sign in to comment.