Search code examples
c#umbracoumbraco-contour

Is there any way to hook to an event when a form is archived withing Umbraco contour? Using Umbraco 4.7.2 and Umbraco Contour 1.12?


I am trying to create a feature where I can track when a form is archived when Using Umbraco Contour. Typically Umbraco code base has a series of events which I can hook into. However I don't see one here.

The other idea was to have a trigger or something on the database but wanted to see if there was a code only solution to this approach.


Solution

  • As far as I know there isn't any specific event that's raised when a form is archived, but you could try subscribing to the FormStorage.FormUpdated event and from there check if the form is archived, then execute your code:

    using System;
    using umbraco.BusinessLogic;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Data.Storage;
    
    public class FormArchiveListener : ApplicationBase
    {
        public FormArchiveListener()
        {
            FormStorage.FormUpdated += new EventHandler<FormEventArgs>(FormStorage_FormUpdated);
        }
    
        void FormStorage_FormUpdated(object sender, FormEventArgs e)
        {
            FormStorage storage = (FormStorage) sender;
    
            if (e.Form.Archived)
            {
                ...
            }
        }
    }