From b4f9dc7b66bb84ef1623e0dd1e46708aea6dc5e7 Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 9 Apr 2021 09:59:53 +0200 Subject: [PATCH] Make CreateTemplateForContentType non nullable and default to false. --- .../Notifications/TemplateSavedNotification.cs | 10 ++++++++-- .../Notifications/TemplateSavingNotification.cs | 10 ++++++++-- .../ModelsBuilder/ModelsBuilderNotificationHandler.cs | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Infrastructure/Services/Notifications/TemplateSavedNotification.cs b/src/Umbraco.Infrastructure/Services/Notifications/TemplateSavedNotification.cs index 284082974c..94152acabc 100644 --- a/src/Umbraco.Infrastructure/Services/Notifications/TemplateSavedNotification.cs +++ b/src/Umbraco.Infrastructure/Services/Notifications/TemplateSavedNotification.cs @@ -20,12 +20,18 @@ namespace Umbraco.Cms.Infrastructure.Services.Notifications { } - public bool? CreateTemplateForContentType + public bool CreateTemplateForContentType { get { State.TryGetValue(s_templateForContentTypeKey, out var result); - return result as bool?; + + if (result is not bool createTemplate) + { + return false; + } + + return createTemplate; } set => State[s_templateForContentTypeKey] = value; } diff --git a/src/Umbraco.Infrastructure/Services/Notifications/TemplateSavingNotification.cs b/src/Umbraco.Infrastructure/Services/Notifications/TemplateSavingNotification.cs index 4d7590098f..7c2408fdad 100644 --- a/src/Umbraco.Infrastructure/Services/Notifications/TemplateSavingNotification.cs +++ b/src/Umbraco.Infrastructure/Services/Notifications/TemplateSavingNotification.cs @@ -35,12 +35,18 @@ namespace Umbraco.Cms.Infrastructure.Services.Notifications ContentTypeAlias = contentTypeAlias; } - public bool? CreateTemplateForContentType + public bool CreateTemplateForContentType { get { State.TryGetValue(s_templateForContentTypeKey, out var result); - return result as bool?; + + if (result is not bool createTemplate) + { + return false; + } + + return createTemplate; } set => State[s_templateForContentTypeKey] = value; } diff --git a/src/Umbraco.Web.Common/ModelsBuilder/ModelsBuilderNotificationHandler.cs b/src/Umbraco.Web.Common/ModelsBuilder/ModelsBuilderNotificationHandler.cs index 1c8d00d9aa..4bc2050855 100644 --- a/src/Umbraco.Web.Common/ModelsBuilder/ModelsBuilderNotificationHandler.cs +++ b/src/Umbraco.Web.Common/ModelsBuilder/ModelsBuilderNotificationHandler.cs @@ -98,7 +98,7 @@ namespace Umbraco.Cms.Web.Common.ModelsBuilder } // Don't do anything if we're not requested to create a template for a content type - if (notification.CreateTemplateForContentType is null or false) + if (notification.CreateTemplateForContentType is false) { return; }