Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Arjan Woldring 124 posts 231 karma points
    Apr 01, 2014 @ 16:45
    Arjan Woldring
    1

    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:

    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;
                    }
                }
            }
    
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 01, 2014 @ 18:01
    Jeroen Breuer
    104

    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

  • Arjan Woldring 124 posts 231 karma points
    Apr 01, 2014 @ 18:55
    Arjan Woldring
    0

    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!

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 01, 2014 @ 18:57
    Jeroen Breuer
    0

    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

  • Arjan Woldring 124 posts 231 karma points
    Apr 01, 2014 @ 19:03
    Arjan Woldring
    0

    Thanks for your quick reply! Is there somewhere documentation about the speech bubble?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 01, 2014 @ 19:48
  • Arjan Woldring 124 posts 231 karma points
    Apr 02, 2014 @ 10:11
    Arjan Woldring
    0

    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.

  • Mark Drake 133 posts 457 karma points c-trib
    Dec 07, 2014 @ 21:34
    Mark Drake
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft