Created
July 20, 2020 10:45
-
-
Save hartviglarsen/abdf41cc858a4b4629eaa0985956e578 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using Umbraco.Core.Composing; | |
using Umbraco.Core.Events; | |
using Umbraco.Core.Models; | |
using Umbraco.Core.Persistence.Repositories; | |
using Umbraco.Core.Services; | |
using Umbraco.Core.Services.Implement; | |
namespace Adventure.Core | |
{ | |
public class TemplateComposer : ComponentComposer<TemplateComponent> { } | |
public class TemplateComponent : IComponent | |
{ | |
private readonly ITemplateRepository _templateRepository; | |
public TemplateComponent(ITemplateRepository templateRepository) | |
{ | |
_templateRepository = templateRepository; | |
} | |
public void Initialize() | |
{ | |
ContentTypeService.Saving += ContentTypeService_Saving; | |
} | |
private void ContentTypeService_Saving(IContentTypeService sender, SaveEventArgs<IContentType> e) | |
{ | |
var template = _templateRepository.Get("superDuperMasterTemplate"); | |
if (template == null) return; | |
foreach (var entity in e.SavedEntities.Where(x => x.HasIdentity == false)) | |
{ | |
entity.SetDefaultTemplate(template); | |
} | |
} | |
public void Terminate() { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment