Last active
January 22, 2019 14:12
-
-
Save warrenbuckley/44272c58e6c4db32fa454ab27c0bb9bf 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; | |
using Umbraco.Core.Components; | |
using Umbraco.Core.Events; | |
using Umbraco.Core.Models; | |
using Umbraco.Core.Services; | |
using Umbraco.Core.Services.Implement; | |
namespace Umbraco.Web.UI | |
{ | |
[RuntimeLevel(MinLevel = RuntimeLevel.Run)] | |
public class TestCancelSave : IUserComposer | |
{ | |
public void Compose(Composition composition) | |
{ | |
composition.Components().Append<TestCancelSaveComponent>(); | |
} | |
} | |
public class TestCancelSaveComponent : IComponent | |
{ | |
public void Initialize() | |
{ | |
ContentService.Saving += ContentService_Saving; | |
} | |
public void Terminate() | |
{ | |
} | |
private void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e) | |
{ | |
var content = e.SavedEntities.First(); | |
if (content.Name.Contains("error")) | |
{ | |
if (e.CanCancel) | |
{ | |
e.CancelOperation(new EventMessage("PreFlight", "There was a problem with some content", EventMessageType.Error)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment