I would like to write some action handler that publishes documents, I know it was not possible before to use the handlers while publishing documents through code. But who knows ?
My goal is to synchronize structure of a multilanguage site... By example if some one is entering a news item in the english section, when the document is created , I would like to create an unpublished copy of the document in the other languages. Let's say now that the news document has a handler attached that creates some "date/month" structure.... I would like that the copies of the document goes through the same process, So I just need to copy the news item in the main node it belongs to, the action handler will move the document as it does with the original.
Any suggestion is welcome ! But I guess it's more likely a change request :-)
You can indeed write action handlers (events), using ApplicationBase. Here's a link to a wiki article with some examples, and also a good blog post by Richard Soeteman on events:
I wanted to know how can I make those action handlers work if I want to publish a new document in my code (by example in one of those handlers as here below).
That will work to publish a document, I'm not 100% though if it will kick off an AfterPublish event for the document, but I am pretty sure it does. If it does you might run into an infinite loop, so you might need to add
some conditions before the Publish is called. In one case I set a
session variable to handle this
Oki, I just figured out while testing my action handler... I know that was not working with earlier functions of umbraco with eventhandlers or I don't know how they call this :-) ... But I didn't tried since then ! :-)
Running Action handlers through code !
I would like to write some action handler that publishes documents, I know it was not possible before to use the handlers while publishing documents through code. But who knows ?
My goal is to synchronize structure of a multilanguage site... By example if some one is entering a news item in the english section, when the document is created , I would like to create an unpublished copy of the document in the other languages. Let's say now that the news document has a handler attached that creates some "date/month" structure.... I would like that the copies of the document goes through the same process, So I just need to copy the news item in the main node it belongs to, the action handler will move the document as it does with the original.
Any suggestion is welcome ! But I guess it's more likely a change request :-)
Hi Laurent,
You can indeed write action handlers (events), using ApplicationBase. Here's a link to a wiki article with some examples, and also a good blog post by Richard Soeteman on events:
http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events
http://www.richardsoeteman.net/PermaLink,guid,f470b6cf-40da-4aa9-a0d9-7b984fe9bf59.aspx
I've used them in conjunction with the Relationship API to implement a solution similar to what you describe.
-Tom
Thank you Tom , that part I already captured:-)
I wanted to know how can I make those action handlers work if I want to publish a new document in my code (by example in one of those handlers as here below).
Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
{
{
).Index(sender);
(Blablabliblouh)
{
PublishSomeNewDocument that will go through the same process of the application Base
}
}
(Exception ex)
{
umbraco.BusinessLogic.Log.Add(LogTypes.Error, -1,
, ex.Message));
Hi,
Sorry, just saw your other thread :)
Are you wanting to create a new document and publish it? Or publish an existing? To publish an existing the .Publish method should work, see this wiki: http://our.umbraco.org/wiki/reference/api-cheatsheet/publishing-and-republishing
That will work to publish a document, I'm not 100% though if it will kick off an AfterPublish event for the document, but I am pretty sure it does. If it does you might run into an infinite loop, so you might need to add some conditions before the Publish is called. In one case I set a session variable to handle this
If you want to create a brand new document and publish it you can use Document.MakeNew to create it (see http://our.umbraco.org/wiki/reference/api-cheatsheet/creating-a-document), or you may even want to copy the initial document in which case you can use .Copy
-Tom
Oki, I just figured out while testing my action handler... I know that was not working with earlier functions of umbraco with eventhandlers or I don't know how they call this :-) ... But I didn't tried since then ! :-)
Thank you.
is working on a reply...