I used this tutorial to write this patch.
http://dtek.net/blog/extending-drup...