Copied to clipboard

Flag this post as spam?

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


  • aghy 129 posts 308 karma points
    Apr 18, 2011 @ 12:14
    aghy
    0

    DataType Events

    Hi all,

    I have been testing the DataType events and I cant work out when they are suppose to fire. Heres my code:

    using System;
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.datatype;

    public class Handlers : ApplicationBase
    {
    public Handlers(){
    umbraco.cms.businesslogic.datatype.DataTypeDefinition.BeforeSave += new EventHandler<SaveEventArgs>(DataTypeDefinition_BeforeSave);
    umbraco.cms.businesslogic.datatype.DataTypeDefinition.New += new DataTypeDefinition.NewEventHandler(DataTypeDefinition_New);
    umbraco.cms.businesslogic.datatype.DataTypeDefinition.Saving += new DataTypeDefinition.SaveEventHandler(DataTypeDefinition_Saving);
    umbraco.cms.businesslogic.datatype.DataTypeDefinition.Deleting += new DataTypeDefinition.DeleteEventHandler(DataTypeDefinition_Deleting);
    }

    void DataTypeDefinition_Deleting(DataTypeDefinition sender, EventArgs e){
    Log.Add(LogTypes.Debug, 0, "Just to check");
    }

    void DataTypeDefinition_Saving(DataTypeDefinition sender, EventArgs e){
    Log.Add(LogTypes.Debug, 0, "Just to check");
    }

    void DataTypeDefinition_New(DataTypeDefinition sender, EventArgs e){
    Log.Add(LogTypes.Debug, 0, "Just to check");
    }

    void DataTypeDefinition_BeforeSave(object sender, SaveEventArgs e){
    Log.Add(LogTypes.Debug, 0, "Just to check");
    }
    }

    I had break points set on all the Log.Add() functions and the only one I could get to fire was the BeforeSave event but this only fired when I saved a DocumentType not DataType as I would expect. I couldn't get the New, Saving and Deleting events to fire.

    I am trying to add some events to when a DataType is saved in the developer section. Anyone know what I can do?

    Thanks
    Ben

  • david 46 posts 81 karma points
    Apr 18, 2011 @ 13:15
    david
    0

    shouldn't the code in Handlers be more like

     

            DataTypeDefinition.AfterNew +=new EventHandler(DataTypeDefinition_AfterNew);
    DataTypeDefinition.BeforeDelete +=new EventHandler(DataTypeDefinition_BeforeDelete);

    ? That seems to work

     

     

  • aghy 129 posts 308 karma points
    Apr 18, 2011 @ 14:31
    aghy
    0

    Hi David thanks for the reply but I still can't get it to work for me.

    The DataTypeDefinition.New event has started firing when I add a new DataType but none of the others do.

    The event I really want is the BeforeSave but looking at my code I cannot understand where it's going wrong.

    Thanks
    Ben

  • david 46 posts 81 karma points
    Apr 18, 2011 @ 15:26
    david
    0

    The DataTypeDefinition has 7 events to tap into: AfterDelete, AfterMove, AfterNew, AfterSave, BeforeDelete, BeforeMove and BeforeSave. You can attach to them using

     

    DataTypeDefinition.Event += new EventHandler<umbraco.cms.businesslogic.EventArgs>(object sender, umbraco.cms.businesslogic.EventArgs e);

     

    so, for the BeforSave, it looks like this:

    DataTypeDefinition.BeforeSave +=new EventHandler<umbraco.cms.businesslogic.SaveEventArgs>(DataTypeDefinition_BeforeSave);

     

  • aghy 129 posts 308 karma points
    Apr 18, 2011 @ 15:42
    aghy
    0

    Ok thanks again,

    The only difference in the code that you have posted and what I put in my original post is the namespace before the DataTypeDefinition. So to me they look exactly the same.

    And even changing it to your code it seems as though the BeforeSave event is getting fired when I save a DocumentType not the DataType. I think there may be something else going on here I will have a look at the umbraco source and see if I can work out whats going on.

    Thanks for your help.
    Ben

  • aghy 129 posts 308 karma points
    Apr 19, 2011 @ 02:17
    aghy
    0

    Does anyone know whether or not the BeforeSave event should fire when saving a DataType?

    I'm using v4.7 and it doesn't seem to fire

    Thanks
    Ben

  • Eran Meir 401 posts 543 karma points
    Jan 11, 2013 @ 10:28
    Eran Meir
    0

    seems like im getting this problem too, anyone got a solution yet?

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Feb 25, 2013 @ 21:15
    Kevin Jump
    0

    i've had the same issue - i have code firing for all other backoffice events on macros, documenttypes, stylesheets, templates... but not on the save events for DataTypes. 

    I have tried the diffrent types of constructor. - still no luck. I've browsed the umbraco source code, can't actually see how DataTypes are saved at all! - can see where prevalues are - can see where the status bubble is fired too.

    DataTypes appear to be written diffrently in the source to all the other types - like they where written ages ago and haven't been updated to new methods since (hence the .Saving while everything else has .AfterSave )

    anyway - I've logged a issue http://issues.umbraco.org/issue/U4-1781 ;

     

Please Sign in or register to post replies

Write your reply to:

Draft