/ Published in: PHP
Sets a module's weight to the lowest number. This assures that your module is ran before all other modules. Userfull if you want your implementation of a hook to be ran first. Add this to your .install file. Replace your_modulename with the name of your module.
Expand |
Embed | Plain Text
function your_modulename_install() { switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': $weight = db_result(db_query('SELECT MIN(weight) AS weight FROM {system} WHERE status = 1')) - 1; db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight, 'your_modulename'); break; default: drupal_set_message(t('Your database type is not supported')); } }
Comments
Subscribe to comments
You need to login to post a comment.

Nice. How about making sure it's the last one run (warning: untested): $weight = dbresult(dbquery('SELECT MAX(weight) AS weight FROM SYSTEM WHERE status = 1')) +1;
Your db_query syntax is not quite right. "SYSTEM" instead of "{system}". "weight = %s" instead of "weight = %d".
@wimLeers: correct. I've corrected this.
@oadaeh, that is about it. If I need a module to run last, and therefore developed that code, i'll submit it on this site :)