How to catch changes in a page in Edit-mode

Topics: Writing modules
Dec 7, 2011 at 11:33 AM

I'm trying to create a feature that would allow me to know when a page's url has been updated

From what I read (and I read ...), I've got a few ideas about how to do this :

- I think I need a contenthandler to catch the update phase of the item
- a contentpart that would need to be added on the contentitem - a page in this case

but then, I have absolutely no idea how to wire all this together nor how to actually write this ... 

(full disclosure : I've never developed a module for orchard before ... oh well I did code a redirection module, but frankly nothing to be very proud of :) )

Can someone give me a hand ? Thanks ...

Dec 7, 2011 at 3:21 PM

You probably don't even need a content part. A ContentHandler can be applied to all content items, or you can target a specific part. Rather than PagePart, I'd target RoutePart, so then anything with routing gets the new behaviour automatically.

All you need to do is:

- Create a module (well, you already have one created, so you can just add this code there)

- Add a class like this:

public class RedirectContentHandler : ContentHandler {

  public RedirectContentHandler() {
    OnPublishing((publishing,part)=>{
      // Here you have access to the context (publishing) and the RoutePart (part)
    });
  }

}
This will automagically get wired into the content pipline. With a ContentHandler you attach to events in the constructor (this works a bit differently from some other extension points).

There are a number of events that you can attach to as well as Publishing. Perhaps Versioning would be most appropriate since it gets called when a new version of an item is saved. If you need more pointers let me know!