From 69acaabec1a2f48fc60b263eb402cafba2c62eb1 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 8 Aug 2018 15:35:02 +1000 Subject: [PATCH] Fixes creating doc types, some null checks missing and an issue with how umbgridselector is responsible for syncing the template alias on a new doc type --- .../views/documenttypes/edit.controller.js | 21 +++++++++++++++++++ .../Editors/ContentTypeControllerBase.cs | 2 +- .../Mapping/ContentTypeMapperProfile.cs | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js index 30c2b493da..197a6edc3a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js @@ -305,6 +305,9 @@ // reformat allowed content types to array if id's vm.contentType.allowedContentTypes = contentTypeHelper.createIdArray(vm.contentType.allowedContentTypes); + //if this is a new item and it's creating a template, ensure that the template alias is synced correctly + syncTemplateAlias(vm.contentType); + return contentEditingHelper.contentEditorPerformSave({ saveMethod: contentTypeResource.save, scope: $scope, @@ -411,6 +414,24 @@ vm.contentType = contentType; } + /** Syncs the template alias for new doc types before saving if a template is to be created */ + function syncTemplateAlias(contentType) { + if (!noTemplate && contentType.id === 0) { + //sync default template that had the placeholder flag + if (contentType.defaultTemplate !== null && contentType.defaultTemplate.placeholder) { + contentType.defaultTemplate.name = contentType.name; + contentType.defaultTemplate.alias = contentType.alias; + } + //sync allowed templates that had the placeholder flag + angular.forEach(contentType.allowedTemplates, function (allowedTemplate) { + if (allowedTemplate.placeholder) { + allowedTemplate.name = contentType.name; + allowedTemplate.alias = contentType.alias; + } + }); + } + } + function convertLegacyIcons(contentType) { // make array to store contentType icon var contentTypeArray = []; diff --git a/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs b/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs index ca7cc54bd9..0764e18eeb 100644 --- a/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs +++ b/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs @@ -275,7 +275,7 @@ namespace Umbraco.Web.Editors catch (Exception ex) { var responseEx = CreateInvalidCompositionResponseException(ex, contentTypeSave, ct, ctId); - if (responseEx != null) throw responseEx; + throw responseEx ?? ex; } var exResult = CreateCompositionValidationExceptionIfInvalid(contentTypeSave, newCt); diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeMapperProfile.cs index 407fd64372..f70b01a422 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeMapperProfile.cs @@ -28,6 +28,7 @@ namespace Umbraco.Web.Models.Mapping dest.AllowedTemplates = source.AllowedTemplates .Where(x => x != null) .Select(fileService.GetTemplate) + .Where(x => x != null) .ToArray(); if (source.DefaultTemplate != null)