Drupal Module Weight

Sometimes you will be executing a form alter and the $form object passed to you does not match what is coming out on the screen. This is most likely that another module is running after your form alter and changing the form.

So the solution is make your module execute after all the other modules have finished. You can do this by changing the system weight. There are 2 ways of doing this, the first is to install the module order module which is in development at the moment but should do the trick.

The second way is to change the database with a script. Its just a one liner and it changes the weight field from 0 to 1. If you want the opposite to happen so you want your module to execute before any others set the weight to -1. All other module have a default weight of 0.

update bookseller.system set weight = 1 where name = ‘my_module’;