Copied to clipboard

Flag this post as spam?

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


  • atze187 160 posts 215 karma points
    Jul 15, 2010 @ 16:26
    atze187
    0

    Action handler for Document.New

    Hi,

    I've created an action handler and want to cancel the creation of a new document using with the code below:

            public AppBase()
            {
                Document.New += new Document.NewEventHandler(Document_New);
            }
    
            void Document_New(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
            {
                bool cancelNew = false;
                if (MultiLanguageSiteManager.Instance.AllowClientDocumentsWithoutMasterDocument == false)
                {
                    if (MultiLanguageSiteManager.Instance.IsClientDocument(sender.Id))
                    {
                        cancelNew = true;
                    }
                }
    
                if (cancelNew == true)
                {
                    e.Cancel = true;
                }
                else
                {
                    if (MultiLanguageSiteManager.Instance.IsMasterDocument(sender.Id))
                    {
                        MultiLanguageSiteManager.Instance.CreateClientDocumentsFromMasterDocument(sender);
                    }
                }
            }
    

    I thought that set e.Cancel = true; would do the job, but the document gets created. Is Document.New the wrong for that OR did I ran into a bug OR is my code erroneous?

    TIA,
    atze

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Jul 15, 2010 @ 16:36
    Tim
    1

    I think that by the time you get to Document.Save it's already there, I think there's a BeforeSave event handler that fires before then (although I could be wrong). If you're using Umbraco 4.5 you should be ok 'cos @slace did some work on the events, but if you're on 4.0.x .Save doesn't actually do anything:

    http://www.aaron-powell.com/the-great-umbraco-api-misconception

    Hope that helps!

  • atze187 160 posts 215 karma points
    Jul 15, 2010 @ 17:44
    atze187
    0

    Thanks Tim, so I guess, I'll have to suppress the "New" context menu item as long as I am on v4.0.x

  • atze187 160 posts 215 karma points
    Jul 15, 2010 @ 18:29
    atze187
    0

    Just checked the v4.5 source and most likely I will upgrade (which was on my agenda anyway), since v4.5 has a Document.Newing event which seems to do what I need. Big up @slace for refactoring the event stuff.

  • Kim Løwert 130 posts 116 karma points
    Jul 30, 2010 @ 16:19
    Kim Løwert
    0

    Hi Atze

    Have you upgraded and testet your Action Handler in 4.5? And if so does it work/fire the event? And if it does, can you post the full eventhandler code incl. class, namespaces etc.?

    I have a Document.New eventhandler that just does not work after upgrading to 4.5 and I would like to upgrade the package I have made. See my thread.

    Thanks a lot in advance :)

    Kim

Please Sign in or register to post replies

Write your reply to:

Draft