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?
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:
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.
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.
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:
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
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!
Thanks Tim, so I guess, I'll have to suppress the "New" context menu item as long as I am on v4.0.x
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.
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
is working on a reply...