设置Drupal模块重量

时间:2011-01-12 16:37:33

标签: drupal drupal-modules

开发自定义模块时,设置模块重量的正确方法是什么?

3 个答案:

答案 0 :(得分:25)

这是在Drupal 7中执行此操作的正确方法

/**
 * Implements hook_enable()
 */
function YOUR_MODULE_enable() {
    db_update('system')
    ->fields(array('weight' => 1))
    ->condition('type', 'module')
    ->condition('name', 'YOUR_MODULE')
    ->execute();
}

答案 1 :(得分:19)

标准方法是在安装挂钩的查询中执行此操作。

来自devel模块:

/**
 * Implementation of hook_install()
 */
function devel_install() {
  drupal_install_schema('devel');

  // New module weights in core: put devel as the very last in the chain.
  db_query("UPDATE {system} SET weight = 88 WHERE name = 'devel'");

  ...
}

答案 2 :(得分:4)

如果由于某种原因你必须将它放在更新钩子中,你需要正确地从update_sql返回结果,以免你看到令人讨厌的无害错误。

function mymodule_update_6000(&$sandbox) {
  $res[] = update_sql("UPDATE {system} SET weight = 1 WHERE name = 'mymodule'");
  return $res;
}
相关问题