Copied to clipboard

Flag this post as spam?

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


  • Dennis Milandt 190 posts 517 karma points
    Jul 06, 2009 @ 11:54
    Dennis Milandt
    1

    Document.AfterNew actionhandler

    Is the Document.AfterNew signature supposed to take an object (CMSNode) and not a Document type as sender? If you cast the object to CMSNode and creates a new Document object from the CMSNode ID you will find that the ContentType property is null.

    I would like to add some text to a property for certain Document Types when created, but I can't find any way to do this using the new actionhandlers. I could still use the IActionHandler interface I suppose.. but is this the only way to achieve what I want?

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jul 06, 2009 @ 12:08
    Darren Ferguson
    0

    I thought it would take a Document as a sender not a DocumentType.

    Which version of Umbraco are you running? I have read somewhere that there were a few event issues in earlier 4.0.x versions.

     

  • Dennis Milandt 190 posts 517 karma points
    Jul 06, 2009 @ 12:19
    Dennis Milandt
    0

    The sender is of the type object and can be casted to a CMSNode.

    I am using 4.0.2.1

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jul 06, 2009 @ 12:40
    Aaron Powell
    4

    I've actually be doing some tweaks to the New event handlers (did you know there's no BeforeNew event, yet there are two post-new events!) early this evening.

    The reason that AfterNew returns you a CMSNode is because it is actually on the CMSNode object, not the Document object (the Document object has a New event though). AfterNew is passed in the CMSNode (which is the base class of Document) but it is actually a bit of a problem, because the CMSNode.MakeNew, which ultimately raises the CMSNode.AfterNew event, is actually fired before the Document is really made. At the point of the CMSNode.AfterNew there has been nothing inserted into the cmsDocument table.

    Unfortunately I don't think this is something that will be changed, it's too much of a restructure of the database record insersion. If you want a post-event for Document creation use the Document.New event.

    One last note, I'm actually adding a Document.Newing (although I should call it BeforeNew which I hate, it's completely against the rest of the .NET framework event naming conventions :( ) which will allow you to actually cancel document creation! That + the other changes to the Document saving event model I've done means you're going to be able to cancel a document when it's created or when it's saving an existing document (without having the database touched, as I pointed out here: http://www.aaron-powell.com/blog/july-2009/the-great-umbraco-api-misconception.aspx).

    Hopefully other people will find the event model useful and I'm not just the only one who's going to use it :P

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 06, 2009 @ 12:43
    Dirk De Grave
    2

    @slace: others will use it for sure, including me. I'm quite confident this issue has been raised on Codeplex as well, but didn't get the attention it deserves. I've ran into this issue as well, and thought I've voted for it on Codeplex (not sure anymore).

    It's great to see you "cleaning" up the stuff, heads up for that, a well deserved vote from me on this forum (apparently, i do get karma points for that as well ;)

  • Dennis Milandt 190 posts 517 karma points
    Jul 06, 2009 @ 17:55
    Dennis Milandt
    0

    @slace: excellent. Somehow I missed the Document.New event. Thanks a lot!

  • Dennis Milandt 190 posts 517 karma points
    Jul 06, 2009 @ 17:57
    Dennis Milandt
    0

    Hm, I click the Mark as solved for Slaces post, but it doesn't seem to work. When the page is refreshed the karma is back to "2", and it's not marked any longer.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jul 07, 2009 @ 00:51
    Aaron Powell
    0

    It could be to do with the updates the did last night to the forum, try again and if it still fails pop a bug in the bugs forum

Please Sign in or register to post replies

Write your reply to:

Draft