diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js index 01fff53931..a33e85c9a2 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js @@ -57,7 +57,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { * Do stuff... * }); * - * + * * @returns {Promise} resourcePromise object. * */ @@ -691,11 +691,12 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { getScaffoldByKeys: function (parentId, scaffoldKeys) { return umbRequestHelper.resourcePromise( - $http.get( + $http.post( umbRequestHelper.getApiUrl( "contentApiBaseUrl", - "GetEmptyByKeys", - { contentTypeKeys: scaffoldKeys, parentId: parentId })), + "GetEmptyByKeys"), + { contentTypeKeys: scaffoldKeys, parentId: parentId } + ), 'Failed to retrieve data for empty content items ids' + scaffoldKeys.join(", ")) .then(function (result) { Object.keys(result).map(function(key) { @@ -804,7 +805,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { else if (options.orderDirection === "desc") { options.orderDirection = "Descending"; } - + //converts the value to a js bool function toBool(v) { if (Utilities.isNumber(v)) { diff --git a/src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js b/src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js index 4bcbbc89d6..ee96cfbaaa 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js @@ -487,7 +487,7 @@ * @returns {Object | null} Scaffold model for the that content type. Or null if the scaffolding model dosnt exist in this context. */ getScaffoldFromKey: function (contentTypeKey) { - return this.scaffolds.find(o => o.contentTypeKey === contentTypeKey); + return this.scaffolds.find(o => o.contentTypeKey === contentTypeKey) || null; }, /** @@ -499,7 +499,7 @@ * @returns {Object | null} Scaffold model for the that content type. Or null if the scaffolding model dosnt exist in this context. */ getScaffoldFromAlias: function (contentTypeAlias) { - return this.scaffolds.find(o => o.contentTypeAlias === contentTypeAlias); + return this.scaffolds.find(o => o.contentTypeAlias === contentTypeAlias) || null; }, /** @@ -609,10 +609,14 @@ blockObject.settingsData = settingsData; // make basics from scaffold - blockObject.settings = Utilities.copy(settingsScaffold); - ensureUdiAndKey(blockObject.settings, settingsUdi); + if (settingsScaffold !== null) {// We might not have settingsScaffold + blockObject.settings = Utilities.copy(settingsScaffold); + ensureUdiAndKey(blockObject.settings, settingsUdi); - mapToElementModel(blockObject.settings, settingsData); + mapToElementModel(blockObject.settings, settingsData); + } else { + blockObject.settings = null; + } // add settings content-app appendSettingsContentApp(blockObject.content, this.__labels.settingsName); diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 55eee7b2a2..8293d1274f 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -449,6 +449,13 @@ namespace Umbraco.Web.Editors return result; } + private IDictionary GetEmptyByKeysInternal(Guid[] contentTypeKeys, int parentId) + { + using var scope = _scopeProvider.CreateScope(autoComplete: true); + var contentTypes = Services.ContentTypeService.GetAll(contentTypeKeys).ToList(); + return GetEmpties(contentTypes, parentId).ToDictionary(x => x.ContentTypeKey); + } + /// /// Gets a collection of empty content items for all document types. /// @@ -457,9 +464,22 @@ namespace Umbraco.Web.Editors [OutgoingEditorModelEvent] public IDictionary GetEmptyByKeys([FromUri] Guid[] contentTypeKeys, [FromUri] int parentId) { - using var scope = _scopeProvider.CreateScope(autoComplete: true); - var contentTypes = Services.ContentTypeService.GetAll(contentTypeKeys).ToList(); - return GetEmpties(contentTypes, parentId).ToDictionary(x => x.ContentTypeKey); + return GetEmptyByKeysInternal(contentTypeKeys, parentId); + } + + /// + /// Gets a collection of empty content items for all document types. + /// + /// + /// This is a post request in order to support a large amount of GUIDs without hitting the URL length limit. + /// + /// + /// + [HttpPost] + [OutgoingEditorModelEvent] + public IDictionary GetEmptyByKeys(ContentTypesByKeys contentTypeByKeys) + { + return GetEmptyByKeysInternal(contentTypeByKeys.ContentTypeKeys, contentTypeByKeys.ParentId); } [OutgoingEditorModelEvent] diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentTypesByKeys.cs b/src/Umbraco.Web/Models/ContentEditing/ContentTypesByKeys.cs new file mode 100644 index 0000000000..8bf1d452bc --- /dev/null +++ b/src/Umbraco.Web/Models/ContentEditing/ContentTypesByKeys.cs @@ -0,0 +1,27 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; + +namespace Umbraco.Web.Models.ContentEditing +{ + /// + /// A model for retrieving multiple content types based on their keys. + /// + [DataContract(Name = "contentTypes", Namespace = "")] + public class ContentTypesByKeys + { + /// + /// ID of the parent of the content type. + /// + [DataMember(Name = "parentId")] + [Required] + public int ParentId { get; set; } + + /// + /// The id of every content type to get. + /// + [DataMember(Name = "contentTypeKeys")] + [Required] + public Guid[] ContentTypeKeys { get; set; } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 4dce8a2da0..e830722cc7 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -241,6 +241,7 @@ +