// Copyright (c) Umbraco. // See LICENSE for more details. using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; namespace Umbraco.Cms.Core.Notifications; /// /// A notification that is used to trigger the IFileService when the SaveTemplate method is called in the API. /// public class TemplateSavingNotification : SavingNotification { private const string TemplateForContentTypeKey = "CreateTemplateForContentType"; private const string ContentTypeAliasKey = "ContentTypeAlias"; public TemplateSavingNotification(ITemplate target, EventMessages messages) : base(target, messages) { } public TemplateSavingNotification(IEnumerable target, EventMessages messages) : base(target, messages) { } /// /// Initializes a new instance of the /// /// /// Initializes a new instance of the . /// /// /// Initializes a new instance of the . /// /// /// Boolean value determining if the template is created for a Document Type. It's not recommended to change this value. /// /// /// This is the alias of the ContentType the template is for. This is used when creating a Document Type with Template. It's not recommended to try and change or set this. /// public TemplateSavingNotification(ITemplate target, EventMessages messages, bool createTemplateForContentType, string contentTypeAlias) : base(target, messages) { CreateTemplateForContentType = createTemplateForContentType; ContentTypeAlias = contentTypeAlias; } /// /// Initializes a new instance of the /// /// /// Gets a enumeration of the . /// /// /// Initializes a new instance of the . /// /// /// Boolean value determining if the template is created for a Document Type. It's not recommended to change this value. /// /// /// This is the alias of the ContentType the template is for. This is used when creating a Document Type with Template. It's not recommended to try and change or set this. /// public TemplateSavingNotification(IEnumerable target, EventMessages messages, bool createTemplateForContentType, string contentTypeAlias) : base(target, messages) { CreateTemplateForContentType = createTemplateForContentType; ContentTypeAlias = contentTypeAlias; } public bool CreateTemplateForContentType { get { if (State?.TryGetValue(TemplateForContentTypeKey, out var result) ?? false) { if (result is not bool createTemplate) { return false; } return createTemplate; } return false; } set { if (!value is bool && State is not null) { State[TemplateForContentTypeKey] = value; } } } public string? ContentTypeAlias { get { if (State?.TryGetValue(ContentTypeAliasKey, out var result) ?? false) { return result as string; } return null; } set { if (value is not null && State is not null) { State[ContentTypeAliasKey] = value; } } } }