From a20cc60c10f8a9fe0569ac0d44e893d8a59dfe6e Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 8 Feb 2017 16:15:27 +1100 Subject: [PATCH] Updates new UDI pickers that have start nodes for pre-values to also store UDIs for their prevalues, this has a knock on effect in that we need to be able to inject some server side config for pre-value editors (otherwise we'd have to make diff udi prevalue editors but that isn't very re-usable), so have implemented that and then updated all of the logic to deal with the udi idType. --- .../PropertyEditors/PreValueField.cs | 7 ++ .../datatypes/datatype.edit.controller.js | 3 +- .../prevalueeditors/mediapicker.controller.js | 21 ++++-- .../prevalueeditors/treepicker.controller.js | 32 +++++---- .../prevalueeditors/treesource.controller.js | 12 +++- .../contentpicker/contentpicker.controller.js | 12 ++-- src/Umbraco.Web/Editors/MediaController.cs | 41 +++++++++++- .../Editors/MediaTypeController.cs | 34 ++++++++-- .../ContentEditing/PreValueFieldDisplay.cs | 9 ++- .../ContentPickerPropertyEditor.cs | 41 ++++++++++-- .../MediaPickerPropertyEditor.cs | 45 +++++++++---- .../MultiNodeTreePickerPropertyEditor.cs | 66 +++++++++++++++---- .../MultipleMediaPickerPropertyEditor.cs | 12 ++++ .../Trees/ContentTreeControllerBase.cs | 11 +++- 14 files changed, 274 insertions(+), 72 deletions(-) diff --git a/src/Umbraco.Core/PropertyEditors/PreValueField.cs b/src/Umbraco.Core/PropertyEditors/PreValueField.cs index 3cf4e960ea..2b66f7a6a8 100644 --- a/src/Umbraco.Core/PropertyEditors/PreValueField.cs +++ b/src/Umbraco.Core/PropertyEditors/PreValueField.cs @@ -15,6 +15,7 @@ namespace Umbraco.Core.PropertyEditors public PreValueField() { Validators = new List(); + Config = new Dictionary(); //check for an attribute and fill the values var att = GetType().GetCustomAttribute(false); @@ -79,5 +80,11 @@ namespace Umbraco.Core.PropertyEditors /// [JsonProperty("validation", ItemConverterType = typeof(ManifestValidatorConverter))] public List Validators { get; private set; } + + /// + /// This allows for custom configuration to be injected into the pre-value editor + /// + [JsonProperty("config")] + public IDictionary Config { get; set; } } } \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/datatypes/datatype.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/datatypes/datatype.edit.controller.js index 02d5a62432..74d35201c2 100644 --- a/src/Umbraco.Web.UI.Client/src/views/datatypes/datatype.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/datatypes/datatype.edit.controller.js @@ -27,7 +27,8 @@ function DataTypeEditController($scope, $routeParams, $location, appState, navig description: preVals[i].description, label: preVals[i].label, view: preVals[i].view, - value: preVals[i].value + value: preVals[i].value, + config: preVals[i].config, }); } } diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/mediapicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/mediapicker.controller.js index 38dd99c204..86e95a8794 100644 --- a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/mediapicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/mediapicker.controller.js @@ -13,9 +13,15 @@ function mediaPickerController($scope, dialogService, entityResource, $log, icon multiPicker: false, entityType: "Media", section: "media", - treeAlias: "media" + treeAlias: "media", + idType: "int" }; + //combine the dialogOptions with any values returned from the server + if ($scope.model.config) { + angular.extend(dialogOptions, $scope.model.config); + } + $scope.openContentPicker = function() { $scope.contentPickerOverlay = dialogOptions; $scope.contentPickerOverlay.view = "treePicker"; @@ -53,18 +59,21 @@ function mediaPickerController($scope, dialogService, entityResource, $log, icon }; $scope.add = function (item) { + + var itemId = dialogOptions.idType === "udi" ? item.udi : item.id; + var currIds = _.map($scope.renderModel, function (i) { - return i.id; + return dialogOptions.idType === "udi" ? i.udi : i.id; }); - if (currIds.indexOf(item.id) < 0) { + if (currIds.indexOf(itemId) < 0) { item.icon = iconHelper.convertFromLegacyIcon(item.icon); - $scope.renderModel.push({name: item.name, id: item.id, icon: item.icon}); + $scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon, udi: item.udi }); } }; var unsubscribe = $scope.$on("formSubmitting", function (ev, args) { var currIds = _.map($scope.renderModel, function (i) { - return i.id; + return dialogOptions.idType === "udi" ? i.udi : i.id; }); $scope.model.value = trim(currIds.join(), ","); }); @@ -79,7 +88,7 @@ function mediaPickerController($scope, dialogService, entityResource, $log, icon entityResource.getByIds(modelIds, dialogOptions.entityType).then(function (data) { _.each(data, function (item, i) { item.icon = iconHelper.convertFromLegacyIcon(item.icon); - $scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon }); + $scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon, udi: item.udi }); }); }); diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treepicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treepicker.controller.js index d2ff7bd778..48edf6e3a1 100644 --- a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treepicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treepicker.controller.js @@ -12,26 +12,29 @@ angular.module('umbraco') multiPicker: false, entityType: "Document", type: "content", - treeAlias: "content" - }; + treeAlias: "content", + idType: "int" + }; + + //combine the config with any values returned from the server + if ($scope.model.config) { + angular.extend(config, $scope.model.config); + } if($scope.model.value){ $scope.ids = $scope.model.value.split(','); entityResource.getByIds($scope.ids, config.entityType).then(function (data) { _.each(data, function (item, i) { item.icon = iconHelper.convertFromLegacyIcon(item.icon); - $scope.renderModel.push({name: item.name, id: item.id, icon: item.icon}); - }); + $scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon, udi: item.udi }); + }); }); } $scope.openContentPicker = function() { - $scope.treePickerOverlay = {}; - $scope.treePickerOverlay.section = config.type; - $scope.treePickerOverlay.treeAlias = config.treeAlias; - $scope.treePickerOverlay.multiPicker = config.multiPicker; + $scope.treePickerOverlay = config; $scope.treePickerOverlay.view = "treePicker"; - $scope.treePickerOverlay.show = true; + $scope.treePickerOverlay.show = true; $scope.treePickerOverlay.submit = function(model) { @@ -64,12 +67,15 @@ angular.module('umbraco') $scope.ids = []; }; - $scope.add =function(item){ - if($scope.ids.indexOf(item.id) < 0){ + $scope.add = function (item) { + + var itemId = config.idType === "udi" ? item.udi : item.id; + + if ($scope.ids.indexOf(itemId) < 0){ item.icon = iconHelper.convertFromLegacyIcon(item.icon); - $scope.ids.push(item.id); - $scope.renderModel.push({name: item.name, id: item.id, icon: item.icon}); + $scope.ids.push(itemId); + $scope.renderModel.push({name: item.name, id: item.id, icon: item.icon, udi: item.udi}); $scope.model.value = trim($scope.ids.join(), ","); } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treesource.controller.js b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treesource.controller.js index ff5e31b8eb..5a53e00e1c 100644 --- a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treesource.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treesource.controller.js @@ -12,7 +12,12 @@ angular.module('umbraco') $scope.model.value = { type: "content" }; - } + } + if (!$scope.model.config) { + $scope.model.config = { + idType: "int" + }; + } if($scope.model.value.id && $scope.model.value.type !== "member"){ var ent = "Document"; @@ -29,7 +34,8 @@ angular.module('umbraco') $scope.openContentPicker =function(){ $scope.treePickerOverlay = { - view: "treepicker", + view: "treepicker", + idType: $scope.model.config.idType, section: $scope.model.value.type, treeAlias: $scope.model.value.type, multiPicker: false, @@ -67,6 +73,6 @@ angular.module('umbraco') $scope.clear(); item.icon = iconHelper.convertFromLegacyIcon(item.icon); $scope.node = item; - $scope.model.value.id = item.id; + $scope.model.value.id = $scope.model.config.idType === "udi" ? item.udi : item.id; } }); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js index 27df035914..01da9cda18 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js @@ -58,7 +58,7 @@ function contentPickerController($scope, entityResource, editorState, iconHelper startNode: { query: "", type: "content", - id: $scope.model.config.startNodeId ? $scope.model.config.startNodeId : -1 // get start node for simple Content Picker + id: $scope.model.config.startNodeId ? $scope.model.config.startNodeId : -1 // get start node for simple Content Picker } }; @@ -105,10 +105,11 @@ function contentPickerController($scope, entityResource, editorState, iconHelper $scope.clear(); $scope.add(data); } - angularHelper.getCurrentForm($scope).$setDirty(); + angularHelper.getCurrentForm($scope).$setDirty(); }, treeAlias: $scope.model.config.startNode.type, - section: $scope.model.config.startNode.type + section: $scope.model.config.startNode.type, + idType: "int" }; //since most of the pre-value config's are used in the dialog options (i.e. maxNumber, minNumber, etc...) we'll merge the @@ -147,9 +148,10 @@ function contentPickerController($scope, entityResource, editorState, iconHelper if ($scope.model.config.startNode.query) { var rootId = $routeParams.id; entityResource.getByQuery($scope.model.config.startNode.query, rootId, "Document").then(function (ent) { - dialogOptions.startNodeId = ent.id; + dialogOptions.startNodeId = $scope.model.config.idType === "udi" ? ent.udi : ent.id; }); - } else { + } + else { dialogOptions.startNodeId = $scope.model.config.startNode.id; } diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index 77ab9ff6e5..0e191954d6 100644 --- a/src/Umbraco.Web/Editors/MediaController.cs +++ b/src/Umbraco.Web/Editors/MediaController.cs @@ -59,7 +59,7 @@ namespace Umbraco.Web.Editors public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) { controllerSettings.Services.Replace(typeof(IHttpActionSelector), new ParameterSwapControllerActionSelector( - new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetChildren", "id", typeof(int), typeof(Guid), typeof(string)))); + new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetChildren", "id", typeof(int), typeof(Guid), typeof(Udi), typeof(string)))); } } @@ -187,6 +187,7 @@ namespace Umbraco.Web.Editors .Select(Mapper.Map>); } + #region GetChildren /// /// Returns the child media objects - using the entity INT id /// @@ -244,7 +245,7 @@ namespace Umbraco.Web.Editors Direction orderDirection = Direction.Ascending, bool orderBySystemField = true, string filter = "") - { + { var entity = Services.EntityService.GetByKey(id); if (entity != null) { @@ -253,6 +254,39 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(HttpStatusCode.NotFound); } + /// + /// Returns the child media objects - using the entity UDI id + /// + /// + /// + /// + /// + /// + /// + /// + /// + [FilterAllowedOutgoingMedia(typeof(IEnumerable>), "Items")] + public PagedResult> GetChildren(Udi id, + int pageNumber = 0, + int pageSize = 0, + string orderBy = "SortOrder", + Direction orderDirection = Direction.Ascending, + bool orderBySystemField = true, + string filter = "") + { + var guidUdi = id as GuidUdi; + if (guidUdi != null) + { + var entity = Services.EntityService.GetByKey(guidUdi.Guid); + if (entity != null) + { + return GetChildren(entity.Id, pageNumber, pageSize, orderBy, orderDirection, orderBySystemField, filter); + } + } + + throw new HttpResponseException(HttpStatusCode.NotFound); + } + [Obsolete("Do not use this method, use either the overload with INT or GUID instead, this will be removed in future versions")] [EditorBrowsable(EditorBrowsableState.Never)] [UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)] @@ -275,7 +309,8 @@ namespace Umbraco.Web.Editors } throw new HttpResponseException(HttpStatusCode.NotFound); - } + } + #endregion /// /// Moves an item to the recycle bin, if it is already there then it will permanently delete it diff --git a/src/Umbraco.Web/Editors/MediaTypeController.cs b/src/Umbraco.Web/Editors/MediaTypeController.cs index db2a806572..879ffd3d0a 100644 --- a/src/Umbraco.Web/Editors/MediaTypeController.cs +++ b/src/Umbraco.Web/Editors/MediaTypeController.cs @@ -40,7 +40,7 @@ namespace Umbraco.Web.Editors public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) { controllerSettings.Services.Replace(typeof(IHttpActionSelector), new ParameterSwapControllerActionSelector( - new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetAllowedChildren", "contentId", typeof(int), typeof(Guid), typeof(string)))); + new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetAllowedChildren", "contentId", typeof(int), typeof(Guid), typeof(Udi), typeof(string)))); } } @@ -187,6 +187,7 @@ namespace Umbraco.Web.Editors } + #region GetAllowedChildren /// /// Returns the allowed child content type objects for the content item id passed in - based on an INT id /// @@ -247,10 +248,30 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(HttpStatusCode.NotFound); } - - [Obsolete("Do not use this method, use either the overload with INT or GUID instead, this will be removed in future versions")] + + /// + /// Returns the allowed child content type objects for the content item id passed in - based on a UDI id + /// + /// + [UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)] + public IEnumerable GetAllowedChildren(Udi contentId) + { + var guidUdi = contentId as GuidUdi; + if (guidUdi != null) + { + var entity = ApplicationContext.Services.EntityService.GetByKey(guidUdi.Guid); + if (entity != null) + { + return GetAllowedChildren(entity.Id); + } + } + + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + [Obsolete("Do not use this method, use either the overload with INT, GUID or UDI instead, this will be removed in future versions")] [EditorBrowsable(EditorBrowsableState.Never)] - [UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)] + [UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)] public IEnumerable GetAllowedChildren(string contentId) { foreach (var type in new[] { typeof(int), typeof(Guid) }) @@ -260,11 +281,12 @@ namespace Umbraco.Web.Editors { //oooh magic! will auto select the right overload return GetAllowedChildren((dynamic)parsed.Result); - } + } } throw new HttpResponseException(HttpStatusCode.NotFound); - } + } + #endregion /// /// Move the media type diff --git a/src/Umbraco.Web/Models/ContentEditing/PreValueFieldDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/PreValueFieldDisplay.cs index 1e8a7ba088..6879701bde 100644 --- a/src/Umbraco.Web/Models/ContentEditing/PreValueFieldDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/PreValueFieldDisplay.cs @@ -1,4 +1,5 @@ -using System.Runtime.Serialization; +using System.Collections.Generic; +using System.Runtime.Serialization; namespace Umbraco.Web.Models.ContentEditing { @@ -33,5 +34,11 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "view", IsRequired = true)] public string View { get; set; } + /// + /// This allows for custom configuration to be injected into the pre-value editor + /// + [DataMember(Name = "config")] + public IDictionary Config { get; set; } + } } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs index 4f798dc41e..ef66f8740e 100644 --- a/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Umbraco.Core; using Umbraco.Core.PropertyEditors; @@ -16,7 +17,18 @@ namespace Umbraco.Web.PropertyEditors public ContentPickerPropertyEditor() { InternalPreValues["idType"] = "int"; - } + } + + /// + /// overridden to change the pre-value picker to use INT ids + /// + /// + protected override PreValueEditor CreatePreValueEditor() + { + var preValEditor = base.CreatePreValueEditor(); + preValEditor.Fields.Single(x => x.Key == "startNodeId").Config["idType"] = "int"; + return preValEditor; + } } /// @@ -52,12 +64,27 @@ namespace Umbraco.Web.PropertyEditors internal class ContentPickerPreValueEditor : PreValueEditor { - [PreValueField("showOpenButton", "Show open button (this feature is in preview!)", "boolean", Description = " Opens the node in a dialog")] - public string ShowOpenButton { get; set; } - - [PreValueField("startNodeId", "Start node", "treepicker")] - public int StartNodeId { get; set; } - + public ContentPickerPreValueEditor() + { + //create the fields + Fields.Add(new PreValueField() + { + Key = "showOpenButton", + View = "boolean", + Name = "Show open button (this feature is in preview!)", + Description = "Opens the node in a dialog" + }); + Fields.Add(new PreValueField() + { + Key = "startNodeId", + View = "treepicker", + Name = "Start node", + Config = new Dictionary + { + {"idType", "udi"} + } + }); + } } } } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs index 3b16aa2cb7..5da7bf38eb 100644 --- a/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs @@ -67,17 +67,40 @@ namespace Umbraco.Web.PropertyEditors internal class MediaPickerPreValueEditor : PreValueEditor { - [PreValueField("multiPicker", "Pick multiple items", "boolean")] - public bool MultiPicker { get; set; } - - [PreValueField("onlyImages", "Pick only images", "boolean", Description = "Only let the editor choose images from media.")] - public bool OnlyImages { get; set; } - - [PreValueField("disableFolderSelect", "Disable folder select", "boolean", Description = "Do not allow folders to be picked.")] - public bool DisableFolderSelect { get; set; } - - [PreValueField("startNodeId", "Start node", "mediapicker")] - public int StartNodeId { get; set; } + public MediaPickerPreValueEditor() + { + //create the fields + Fields.Add(new PreValueField() + { + Key = "multiPicker", + View = "boolean", + Name = "Pick multiple items" + }); + Fields.Add(new PreValueField() + { + Key = "onlyImages", + View = "boolean", + Name = "Pick only images", + Description = "Only let the editor choose images from media." + }); + Fields.Add(new PreValueField() + { + Key = "disableFolderSelect", + View = "boolean", + Name = "Disable folder select", + Description = "Do not allow folders to be picked." + }); + Fields.Add(new PreValueField() + { + Key = "startNodeId", + View = "mediapicker", + Name = "Start node", + Config = new Dictionary + { + {"idType", "udi"} + } + }); + } } } } diff --git a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs index c3e257962a..fbba130543 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; @@ -14,6 +15,17 @@ namespace Umbraco.Web.PropertyEditors { InternalPreValues["idType"] = "int"; } + + /// + /// overridden to change the pre-value picker to use INT ids + /// + /// + protected override PreValueEditor CreatePreValueEditor() + { + var preValEditor = base.CreatePreValueEditor(); + preValEditor.Fields.Single(x => x.Key == "startNode").Config["idType"] = "int"; + return preValEditor; + } } [PropertyEditor(Constants.PropertyEditors.MultiNodeTreePicker2Alias, "Multinode Treepicker", PropertyEditorValueTypes.Text, "contentpicker", Group="pickers", Icon="icon-page-add")] @@ -45,20 +57,46 @@ namespace Umbraco.Web.PropertyEditors internal class MultiNodePickerPreValueEditor : PreValueEditor { - [PreValueField("startNode", "Node type", "treesource")] - public string StartNode { get; set; } - - [PreValueField("filter", "Allow items of type", "textstring", Description = "Separate with comma")] - public string Filter { get; set; } - - [PreValueField("minNumber", "Minimum number of items", "number")] - public string MinNumber { get; set; } - - [PreValueField("maxNumber", "Maximum number of items", "number")] - public string MaxNumber { get; set; } - - [PreValueField("showOpenButton", "Show open button (this feature is in preview!)", "boolean", Description = " Opens the node in a dialog")] - public string ShowOpenButton { get; set; } + public MultiNodePickerPreValueEditor() + { + //create the fields + Fields.Add(new PreValueField() + { + Key = "startNode", + View = "treesource", + Name = "Node type", + Config = new Dictionary + { + {"idType", "udi"} + } + }); + Fields.Add(new PreValueField() + { + Key = "filter", + View = "textstring", + Name = "Allow items of type", + Description = "Separate with comma" + }); + Fields.Add(new PreValueField() + { + Key = "minNumber", + View = "number", + Name = "Minimum number of items" + }); + Fields.Add(new PreValueField() + { + Key = "maxNumber", + View = "number", + Name = "Maximum number of items" + }); + Fields.Add(new PreValueField() + { + Key = "showOpenButton", + View = "boolean", + Name = "Show open button (this feature is in preview!)", + Description = "Opens the node in a dialog" + }); + } /// /// This ensures the multiPicker pre-val is set based on the maxNumber of nodes set diff --git a/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs index 716e71711f..8bd23a24a6 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Umbraco.Core; using Umbraco.Core.PropertyEditors; @@ -12,6 +13,17 @@ namespace Umbraco.Web.PropertyEditors { //clear the pre-values so it defaults to a multiple picker. InternalPreValues.Clear(); + } + + /// + /// overridden to change the pre-value picker to use INT ids + /// + /// + protected override PreValueEditor CreatePreValueEditor() + { + var preValEditor = base.CreatePreValueEditor(); + preValEditor.Fields.Single(x => x.Key == "startNodeId").Config["idType"] = "int"; + return preValEditor; } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs index 5e8172b29f..2a5e28496e 100644 --- a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs @@ -300,24 +300,31 @@ namespace Umbraco.Web.Trees } /// - /// Get an entity via an id that can be either an integer or a Guid + /// Get an entity via an id that can be either an integer, Guid or UDI /// /// /// internal IUmbracoEntity GetEntityFromId(string id) { IUmbracoEntity entity; + Guid idGuid = Guid.Empty; int idInt; + Udi idUdi; + if (Guid.TryParse(id, out idGuid)) { entity = Services.EntityService.GetByKey(idGuid, UmbracoObjectType); - } else if (int.TryParse(id, out idInt)) { entity = Services.EntityService.Get(idInt, UmbracoObjectType); } + else if (Udi.TryParse(id, out idUdi)) + { + var guidUdi = idUdi as GuidUdi; + entity = guidUdi != null ? Services.EntityService.GetByKey(guidUdi.Guid, UmbracoObjectType) : null; + } else { return null;