Add onBeforeSave() hook to allow for pre-save processing and disabling

Added a hook needed for a project I'm working on which will allow for the user to add an onBeforeSave() hook.  The real diff would be 4 additions, but I indented the 40 lines or so.  Thought it might be useful.