0

I have several custom modules and each one of them serves different functionalities. Each module contains from few to many hook implementations and inevitably there are cases where I have to use a hook more than one times between the modules, hook_menu for example.

What are the downsides (if any) of using the same hooks more than one times in different modules ? Is that recommended ? What about performance?

Thanks!

closed as primarily opinion-based by Pierre.Vriens, Shawn Conn, Adrian Cid Almaguer, Елин Й., Scott Joudry Mar 7 '16 at 12:00

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    The more modules you have installed the worse your performance. – J. Reynolds Mar 4 '16 at 12:22
2

That's exactly how it is supposed to work. Hooks are functions defined by Drupal for you to add functionality to the system through your modules. Hooks are like open doors for you to add things.

From Drupal's documentation:

To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it.

Obviously, the more hooks defined in different modules, performance gets hit. But you can't avoid that. You shouldn't stop adding functionality to your modules through hooks because of this.

  • I was excepting a more in depth answer. I am aware of the drupal's documentation, but there should be some downsides on the hooks re-usage, or at list a way to follow in order to avoid most of those downsides, thank you either way! – mchar Mar 4 '16 at 17:22
  • It's not 'hook re-usage' if its used in different modules. The modules are declaring their functionality and hooking into system events. Obviously if you install 150+ modules, there are going to be performance hits. – Kevin Mar 4 '16 at 18:26
  • What if you have ten modules and hook_form_alter implemented to each one of them ? I don't think that this is recommended. – mchar Mar 7 '16 at 10:38
  • There's nothing wrong with that. If each of those ten modules contains it's own logic, then it's fine. If it is necessary for each of those ten modules to, for example, alter a form, they should implement the corresponding hook. – Javier Ugarte Mar 7 '16 at 12:20
  • Up-vote , but that does not convince me... – mchar Mar 7 '16 at 13:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.