Implment a Renaming & Renamed notification for DataType Container
This commit is contained in:
@@ -2,7 +2,7 @@ using Umbraco.Cms.Core.Models;
|
||||
|
||||
namespace Umbraco.Cms.Core.Events
|
||||
{
|
||||
public class EntityContainerRenamedNotification : SavedNotification<EntityContainer>
|
||||
public class EntityContainerRenamedNotification : RenamedNotification<EntityContainer>
|
||||
{
|
||||
public EntityContainerRenamedNotification(EntityContainer target, EventMessages messages) : base(target, messages)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using Umbraco.Cms.Core.Models;
|
||||
|
||||
namespace Umbraco.Cms.Core.Events
|
||||
{
|
||||
public class EntityContainerRenamingNotification : RenamingNotification<EntityContainer>
|
||||
{
|
||||
public EntityContainerRenamingNotification(EntityContainer target, EventMessages messages) : base(target, messages)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/Umbraco.Core/Events/RenamedNotification.cs
Normal file
20
src/Umbraco.Core/Events/RenamedNotification.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Cms.Core.Events
|
||||
{
|
||||
public abstract class RenamedNotification<T> : EnumerableObjectNotification<T>
|
||||
{
|
||||
protected RenamedNotification(T target, EventMessages messages) : base(target, messages)
|
||||
{
|
||||
}
|
||||
|
||||
protected RenamedNotification(IEnumerable<T> target, EventMessages messages) : base(target, messages)
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<T> Entities => Target;
|
||||
}
|
||||
}
|
||||
20
src/Umbraco.Core/Events/RenamingNotification.cs
Normal file
20
src/Umbraco.Core/Events/RenamingNotification.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Cms.Core.Events
|
||||
{
|
||||
public abstract class RenamingNotification<T> : CancelableEnumerableObjectNotification<T>
|
||||
{
|
||||
protected RenamingNotification(T target, EventMessages messages) : base(target, messages)
|
||||
{
|
||||
}
|
||||
|
||||
protected RenamingNotification(IEnumerable<T> target, EventMessages messages) : base(target, messages)
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<T> Entities => Target;
|
||||
}
|
||||
}
|
||||
@@ -223,10 +223,17 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
|
||||
container.Name = name;
|
||||
|
||||
var renamingEntityContainerNotification = new EntityContainerRenamingNotification(container, evtMsgs);
|
||||
if (scope.Notifications.PublishCancelable(renamingEntityContainerNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Attempt.Cancel(evtMsgs, container);
|
||||
}
|
||||
|
||||
_dataTypeContainerRepository.Save(container);
|
||||
scope.Complete();
|
||||
|
||||
scope.Notifications.Publish(new EntityContainerRenamedNotification(container, evtMsgs));
|
||||
scope.Notifications.Publish(new EntityContainerRenamedNotification(container, evtMsgs).WithStateFrom(renamingEntityContainerNotification));
|
||||
|
||||
return OperationResult.Attempt.Succeed(OperationResultType.Success, evtMsgs, container);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user