From 85c27be2d7bd03ddabfbd6bf44d3432cc4745a8c Mon Sep 17 00:00:00 2001 From: Callum Whyte Date: Mon, 23 May 2022 20:23:25 +0100 Subject: [PATCH] Setting default item type icon in configuration editor --- .../MeganavConfigurationEditor.cs | 23 ++++++++++++++++++- .../propertyeditors/editor.controller.js | 6 ----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Our.Umbraco.Meganav/PropertyEditors/MeganavConfigurationEditor.cs b/src/Our.Umbraco.Meganav/PropertyEditors/MeganavConfigurationEditor.cs index e219044..b7eda9e 100644 --- a/src/Our.Umbraco.Meganav/PropertyEditors/MeganavConfigurationEditor.cs +++ b/src/Our.Umbraco.Meganav/PropertyEditors/MeganavConfigurationEditor.cs @@ -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 @@ -10,5 +13,23 @@ public MeganavConfigurationEditor(IIOHelper ioHelper) { } + + public override IDictionary ToValueEditor(object configuration) + { + var value = base.ToValueEditor(configuration); + + if (value.TryGetValue("itemTypes", out var data) == true) + { + if (data is IEnumerable itemTypes) + { + foreach (var itemType in itemTypes.OfType()) + { + itemType.Icon = itemType.Icon ?? "icon-link"; + } + } + } + + return value; + } } } \ No newline at end of file diff --git a/src/Our.Umbraco.Meganav/Web/UI/App_Plugins/Meganav/backoffice/propertyeditors/editor.controller.js b/src/Our.Umbraco.Meganav/Web/UI/App_Plugins/Meganav/backoffice/propertyeditors/editor.controller.js index 0bedaba..c7faaf1 100644 --- a/src/Our.Umbraco.Meganav/Web/UI/App_Plugins/Meganav/backoffice/propertyeditors/editor.controller.js +++ b/src/Our.Umbraco.Meganav/Web/UI/App_Plugins/Meganav/backoffice/propertyeditors/editor.controller.js @@ -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);