Copied to clipboard

Flag this post as spam?

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


  • Troska 21 posts 41 karma points
    Mar 12, 2012 @ 14:14
    Troska
    0

    DocumentType.AfterSave

    Hi.

    I'm using DocumentType.AfterSave to save a document type that has changed to the file system. However, when I use the sender object or get the document type by alias inside my AfterSave method, the changes haven't taken place. If I save again then I see the changes.

    Is there something that I don't understand? Shouldn't the changes have taken place when the AfterSave event is dispatched?

    Thanks!

  • Troska 21 posts 41 karma points
    Mar 12, 2012 @ 17:26
    Troska
    0

    Upon further investigation it seems that allowedTemplates is the only one that doesn't change in the event, other variables are changing.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Mar 13, 2012 @ 07:41
    Richard Soeteman
    0

    AfterSave should have updated all properties. I think this is a bug, could you report this on Codeplex?

     

  • Troska 21 posts 41 karma points
    Mar 13, 2012 @ 09:43
    Troska
    0

    Yeah I'll probably report it. It happens to two properties of which are allowedTemplates and DefaultTemplate.

    I'm using Umbraco 4.7.1.1

     

    Btw, is there anything else I can do to "fetch" the correct information? If I look at DocumentType class, it's calling base.Save() and then firing the AfterSave, so I'm wondering why this would happen at all because it "looks" correct in the class.

    EDIT: I've added bug report to codeplex: http://umbraco.codeplex.com/workitem/30753

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 13, 2012 @ 10:46
    Lee Kelleher
    0

    Hi Troska,

    Could you provide a small code snippet?  As you mention that in the AfterSave event you are trying to get the DocumentType by Alias... forgive my misunderstanding, wouldn't you already have access to the DocumentType object in the 'sender'?

    Thanks, Lee.

  • Troska 21 posts 41 karma points
    Mar 13, 2012 @ 10:56
    Troska
    0

    @Lee Kelleher

    Yes I do have reference to the DocumentType that is being saved which is the sender object. The changes to the DefaultTemplate and allowedTemplates have not taken place there.

    Regarding DocumentType.GetByAlias, I was just trying to see if the changes have taken place there.

    But basically this is my code snippet:

    private void DocumentType_AfterSave(DocumentType sender, umbraco.cms.businesslogic.SaveEventArgs e)
    {
       Log.Add(umbraco.BusinessLogic.LogTypes.Custom, 0, sender.allowedTemplates.Count().ToString());
    }
     

    So if I check 3 templates in allowedTemplates and press save, then this function will log 0, if I save again it'll log 3. So it seems like the changes for the templates take place after the AfterSave trigger.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 13, 2012 @ 11:28
    Lee Kelleher
    0

    Hi Troska,

    Just taken a look at the Umbraco core (v4.7.1.1)  ... and you are right!

    The page "~/umbraco/settings/EditNodeTypeNew.aspx" separates out the Allow/Default Template controls (and saving) from the rest of the DocumentType functionality, which is in a user-control "~/umbraco/controls/ContentTypeControlNew.ascx".

    Since there are no hooks you can use to access the Allow/Default template on save, you might have to roll your own?  My advice would be to take a look at Tom's Structure Extensions source-code (specifically the 'InjectExtensions.cs' code) ... try hooking into the "EditNodeTypeNew.aspx" page and attaching to the 'OnBubbleEvent'.  It's a pretty wild idea, but might just work! ;-)

    Cheers, Lee.

  • Troska 21 posts 41 karma points
    Mar 13, 2012 @ 15:02
    Troska
    0

    Yeah, I simply created my own class that inherits from EditContentTypeNew and made ContentTypeControlNew.ascx inherit my custom class.

    So I just overrided OnBubbleEvent in my custom class and dispatched my own event there :)

    Thanks for the help Lee Kelleher.

Please Sign in or register to post replies

Write your reply to:

Draft