Today I changed the weight of a custom module of mine in order to change the execution method of hooks (hook_form_alter). I've changed the weight to 1 value heavier than the other module's weight. This seemed the safest thing to do instead of giving it a "random" weight of 100. The original module is a core module (translation) so I hope I didn't break anything.

When adjusting the weight of a module in order to change the execution order of hooks, what are the things to look out for and what are the risks involved?

What I can think of: unwanted behaviour as result of high coupling.

2 Answers 2


Well there isn't a general answer to this, it really depends on the modules. Some of the things I would take into consideration (In Drupal 6) :

  • hook_boot is called as modules are loaded ; so only modules that are lighter than you have been included. If you rely on code from another module that is heavier than you, make sure you include them manually.

  • If a module has by default a weight other than 0, then it means that this module specifically set this weight. Check that module's .install file, as this is most likely where the weight is set - and with a bit of luck there will be a comment explaining why ! (this may be true even if the weight is zero)

  • Modules that set either a very low or very high weight usually have a good reason for it (must run before/after everything else). Typically development modules do this, though others might as well. Keep these modules first/last unless you have a good reason for it.

  • Look at the module's dependencies (the ones the module depends on, and the ones that depend on this module). Ideally keep these modules in the same order. If you must change the order, the only way to understand the consequnces is to look at the code.

  • Use common sense. Information that is added by a module (say to a node on node load) will not be available to modules lighter than this one.

  • 1
    Any differences for Drupal 7?
    – DrCord
    May 1, 2014 at 17:28

I honestly don't think there's a general answer for this. What happens when you adjust the module weight depends highly on the modules involved, and if you change the weights of too many modules, I would imagine that you could end up with some unpredictable results.

That being said, if you want to minimize your risk, just consider precisely what it is that your module is doing. What data are you modifying? Are you making major changes to data structures, or are you changes more cosmetic? The biggest risk, I would think, would be changing existing data in an unexpected way. If you're careful and you adjust module weights sparingly, you shouldn't have too many issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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