Drupal7: Module Weights and Hooks

Upon page load everything in Drupal7 occurs in specific order and this ordering is dependent on a Modules, or Hooks weight. Sometimes if we want to change the default behavior or Drupal or other modules we must be aware of this aspect of Drupal. One way to visualize the ordering of module priority in Drupal is to install the Modules Weight module.

Example module weight on minimal Drupal 7 website.

Example module weight on minimal Drupal 7 website.


The ordering of the module list found at /admin/config/system/modules-weight is the ordering from Top to Bottom which Drupal will invoke modules by. Hooks defined within modules run in the ordering of this list.

By clicking Show Row Weights at the upper right of the table you can see the Weight of the module in the Drupal system. You will see that some modules have an identical weight as other modules. For example in my screenshot a ton of modules are assigned the weight value of 0. Modules assigned the same weight are invoke in alphabetical order based on their machine name.

The modules_weight module allows you to easily to drag-and-drop a module to a different weight — and therefore adjust its invocation order within your Drupal installation. You should be careful when doing this, as it could irrevocably break the system, but with care this can be very powerful. In a future blog post I will make use of this flexibility of Drupal7.

If you want to change the order of your module, without requiring an install of this module (which some might consider bloating your Drupal installation) you can see techniques for assigning weights this in the Drupal Community documentation. Essentially it is a line of code in your module’s .install file.

Looking for quality Drupal Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , | Posted under Drupal | RSS 2.0

Author Spotlight

David Gurba

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *


8 − 6 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>