Hooks are very cool. This is something you should support in your module. What it does is send out a call to any Hook modules that are listening to your module. The example you gave above would notify any hooked in module that a new item, with the unique id $uid has been created.
These lines of code are normally put into your code when you display, create, update or delete something in your module. The listening module can then take appropriate action when it gets these messages. If you are familiar with object programming and the broadcaster=>listener design pattern, hooks are listeners and modules that support hooks are broadcasters.
This design pattern allows for some very neat functionality. Simon gave one example. Any module that supports hooks can have comments added to it just by including the
EZComments module and making the connection between the broadcaster and listener. This is done in the modules admin panel, look for the hooks link. You get all the functionality of a comments module in your hookable module for free.
I have also used it to add a quizzing capability to the Book module that I wrote. Any page in the book can have a quiz added to it. The quiz is created in the Exams module and then hooked up to a Book article. To see an example of this go to
http://www.microbiol…ayarticle&art_id=23 and scroll to the bottom. By having them separate, it promotes code usability. Any other hookable module should be able to attach quizzes.
edited by: Paustian, Apr 08, 2007 - 07:29 PM