Module override another module

Here is the code that makes your module able to override other modules. Drupal uses a modules weight, stored in systems table when loading modules. The higher weight the later your module is loaded. You can use this if form_alter on an other modules form doesn't work and things like that.

<?php
// $Id: $

/**
 *  Sets module weight to plus one from slideshow
 *  to be sure to override form_alter in slideshow.
 *
 */
function mymodule_slideshow_install() {
 
$weight = (int) db_result(db_query("SELECT weight FROM {system} WHERE name = 'slideshow'"));
 
db_query("UPDATE {system} SET weight = %d WHERE name = 'mymodule_slideshow'", $weight + 1);
 
drupal_set_message(t('Has set module weight to plus one from slideshow (%weight) to be sure to override form_alter in slideshow', array('%weight' => $weight)), 'status');
}

function
mymodule_slideshow_uninstall() {
 
drupal_set_message('Uninstalled Mymodule Slideshow', 'status');
}
?>

And a more general version:

<?php
function newsexport_install() {
 
$reference = "node";
 
$my_module = "newsexport";
 
$differing_weight = 1;

 
$weight = (int) db_result(db_query("SELECT weight FROM {system} WHERE name = '%s'", $reference));
 
db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight + $differing_weight, $my_module);
 
drupal_set_message(t('Has set module weight on %my_module to plus %differing_weight from %reference (%weight) to be sure to override %reference functions', array('%weight' => $weight, '%reference' => $reference, '%my_module' => $my_module, '%differing_weight' => $differing_weight)), 'status');
}

function
newsexport_uninstall() {
 
$my_module = "newsexport";
 
drupal_set_message('Uninstalled '.$my_module, 'status');
}
?>
Knowledge keywords: