Skip to content

Instantly share code, notes, and snippets.

@warrenbuckley
Last active January 22, 2019 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warrenbuckley/44272c58e6c4db32fa454ab27c0bb9bf to your computer and use it in GitHub Desktop.
Save warrenbuckley/44272c58e6c4db32fa454ab27c0bb9bf to your computer and use it in GitHub Desktop.
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