I am playing with events in Umbraco 7 but I have an event which seems not to be triggered.
What I am intending to do is cancel the deletion of content node called "Home".
But while debugging, it seems that ContentService_Deleting method isn't hit at all.
I tried ContentService.Saving (in another test) and that is wokring perfectly. So i thought that Deleting would work somewhat the same.
I wonder what I am doing wrong. Any help would be appreciated.
This is what I have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Publishing;
using Umbraco.Core.Services;
namespace CustomEvents
{
public class CustomEvents : ApplicationEventHandler
{
public CustomEvents()
{
ContentService.Deleting += ContentService_Deleting;
}
void ContentService_Deleting(IContentService sender, DeleteEventArgs<IContent> e)
{
foreach (var node in e.DeletedEntities)
{
if (node.Name == "Home")
{
e.Cancel = true;
}
}
}
Yes good point! I was thinking in the wrong direction. What I needed was ContentService.Trashing...overlooked that one.
Do you happen to know how I can force some kind of refresh after the trashing is cancelled? Because the node is visually deleted but it's still there after a refresh in the backend. That the node is still in place is a good thing of course that was my intention but a refresh somehow would be perfect.
Thanks a lot for pointing me in the right direction!
Sorry I don't think that is possible. The events aren't linked to the UI. You can show a cancel message in the speech bubble, but that's it probably. Please mark a post as the solution if it helped you.
Thanks Jeroen. I will try those examples. I just had my reservation because those post were many years old. But if it still applies I think that's fine.
Those examples don't work in Umbraco 7.2 - trying to cast the current handler as a page errors. I'm still trying to figure out how to (1) show a speech bubble inside of an event and (2) cancel the page / tree change, or refresh the entire page because removing a node from the tree when the node was not actually removed is misleading.
ContentService Deleting Event not firing
Hi,
I am playing with events in Umbraco 7 but I have an event which seems not to be triggered.
What I am intending to do is cancel the deletion of content node called "Home". But while debugging, it seems that ContentService_Deleting method isn't hit at all.
I tried ContentService.Saving (in another test) and that is wokring perfectly. So i thought that Deleting would work somewhat the same.
I wonder what I am doing wrong. Any help would be appreciated.
This is what I have:
Hello,
Did you try deleting it by emptying the recycle bin? Otherwise it might not be triggered because it's only being moved to the recycle bin.
Jeroen
Yes good point! I was thinking in the wrong direction. What I needed was ContentService.Trashing...overlooked that one.
Do you happen to know how I can force some kind of refresh after the trashing is cancelled? Because the node is visually deleted but it's still there after a refresh in the backend. That the node is still in place is a good thing of course that was my intention but a refresh somehow would be perfect.
Thanks a lot for pointing me in the right direction!
Hello,
Sorry I don't think that is possible. The events aren't linked to the UI. You can show a cancel message in the speech bubble, but that's it probably. Please mark a post as the solution if it helped you.
Jeroen
Thanks for your quick reply! Is there somewhere documentation about the speech bubble?
Here are some links:
https://groups.google.com/d/msg/umbraco-dev/z3WNxXgotvo/kdtxiAgdLgMJ
http://our.umbraco.org/forum/developers/api-questions/6615-How-do-I-do-create-a-speech-bubble-from-an-event
Jeroen
Thanks Jeroen. I will try those examples. I just had my reservation because those post were many years old. But if it still applies I think that's fine.
Those examples don't work in Umbraco 7.2 - trying to cast the current handler as a page errors. I'm still trying to figure out how to (1) show a speech bubble inside of an event and (2) cancel the page / tree change, or refresh the entire page because removing a node from the tree when the node was not actually removed is misleading.
is working on a reply...