Copied to clipboard

Flag this post as spam?

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


  • Samuel Front 1 post 71 karma points
    Sep 22, 2015 @ 14:26
    Samuel Front
    0

    Hooking into Save Events

    I have a widget which I'd like to hook into the save event for. As far as I can tell, the ContentSavedService event only returns the Content object for the page as a whole, and I then have to dig into Properties, grab the Value and parse the resulting JSON. This, and in particular, the JSON parsing, seems extremely unideal.

    Is there a way to easily get an array/list of widgets on the page being saved so that I can find the one I'm trying to hook into? Or alternatively, a different way of hooking into the save event?

  • Tyler Brown 62 posts 209 karma points
    Sep 22, 2015 @ 15:15
    Tyler Brown
    0

    Are you doing this through angular or through C# class? I usually create a class that inherits from ApplicationEventHandler and then override the ApplicationStarted method:

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
    
        Umbraco.Core.Services.ContentService.Saved += (sender, args) =>
        {
            foreach (var item in args.SavedEntities)
            {
                //find property and do something
            }
        };
    }
    

    As I understand it, the Saved event holds an IEnumerable of IContent objects that are being saved. From there, you can sift down to the property you need. No need to parse JSON, unless I'm misunderstanding your question?

Please Sign in or register to post replies

Write your reply to:

Draft