How to Control Drupal Modules Weights and Execution Order

Ma'moun Othman

One of the good features that Drupal offers to the developer is the module execution order. Out of the box, Drupal has a mechanism to allow it to execute module's hooks in predefined order based on modules weight (order). If you check your Drupal installation's database, there will be a table in your database called system, in this table Drupal stores all the modules and themes (core and contributed) information, including their execution order which is visible in the weight column.

Most of you developers, found your selves in a situation where some of you custom code is not working. Well, most of the time this issue is caused by some other module overriding what you did, or that your module is not executing in the "layer" it should.

To solve this issue, I used to just go directly to my MySQL client and update the module's weight in the system table. But..... What if you don’t have access to the database? What if you do want a nicer way to see the order in which modules are executed?

To solve this issue you might consider using Modules Weight module, this module allows the admins or the webmaster with privilege to access the administration page of this module and modify the modules weight as he/she wishes with a drag-drop feature.

Note: This module by default doesn't display the core modules, that's because displaying core modules in the configuration form will reorder the system core modules execution even if you didn't change them! And as some might notice all core modules has to have 0 weight value by default.