Drupal set module weight

In Drupal, each module has something called weight. The weight, which is stored as an integer, determines when the module's code gets run. Sometimes, you want to alter something that another module does. In order to override another module, your module has to have a higher weight. There is nothing in the UI that lets you change a module's weight. You can set the weight by changing the value in the 'system' database column. To automate this, use something like the following code in your module's .install file:

In mymodule.install:

<?php
function mymodule_install() {
  db_query("UPDATE {system} SET weight = 2000 WHERE type = 'module' AND name = 'mymodule'");
}
?>
Example from uuid_features.install:
<?php
/**
 * Implements hook_enable().
 */
function uuid_features_enable() {
  db_update('system')
    ->fields(array(
      'weight' => -50,
    ))
    ->condition('name', 'uuid_features')
    ->condition('type', 'module')
    ->execute();
}
?>

Internal References

Article Type

General