Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

Examples of Good Mods using Integration Hooks

Aloittaja wixi, marraskuu 21, 2013, 02:00:57 AP

« edellinen - seuraava »

wixi

Can you please point me to some good mods that make use of integration hooks? I am a bit confused on how to use them through modifications.xml and would like to study the source to learn more ... Thanks.

emanuele



Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

wixi

Thanks, I had read that. But I am a bit confused on how modifications.xml and Integration hooks gel together. They seem like two separate ways of doing things ...

Arantor

That's because they are. modifications.xml (or whatever you want to call it, I've been known to have mods with multiple such files to group changes together) is about raw code editing, integration hooks is about not doing code editing at all.

Some mods find they need to do raw code editing because the choices available in terms of hooks may not be enough.
Holder of controversial views, all of which my own.


live627

modifications.xml = code edits
iinstall.php = usually database edits which includes settings and hooks

Some mods boast of only using hooks.

wixi

So, for example, if I wanted to make a mod that added headers or footers to every post made in the forum the two ways to go about it would be -

Raw editing: Find out the "post message" function and modify it (i.e. change the core function) OR
Using hooks: Check for "post message" hook and attach it with your own custom post message function

Is that right?

Arantor

Sort of. Not every function has a hook - fairly sure there isn't a hook in 2.0 for 'post message' for example. (There is one on creation of a new topic, and one for topic display that can be coerced into doing other things, but it's pretty limited.)
Holder of controversial views, all of which my own.


wixi

#7
Ah, ok. One other doubt - after you have added your own custom function to a hook, does the original core function still execute later? Taking the same example I posted - if I add a custom_post_message function to "post message" hook, will the original "post message" core function be called again later (after the custom_post_message function is executed)?

Arantor

The hook is little more than 'when you get to this point, call me' notification. The original code will continue to run exactly as it would otherwise, a hook is merely *additional* code to be run at the selected points.
Holder of controversial views, all of which my own.


wixi

So is there an option to decide whether the custom function runs before or after the core function (in case we are calling a hook that deals with a core function)?

Arantor

No.

Hooks run when they run. There is a shortage of hooks anyway, if you don't have a hook for the specific task at hand, you'll have to just make an edit anyway. The available hooks are documented in the wiki.
Holder of controversial views, all of which my own.


wixi

Thanks for all the clarifications. Much appreciated.

Advertisement: