知识网
  • 主页
  • 建站基础
  • 网页设计
  • 开发代码
  • 网页特效
  • 精品网站
  • 数据库
  • 推广运营
  • 广告视觉
  • 开源系统
  • 电脑常识
  • 游戏攻略
  • 科技资讯
  • 其他
  • 当前位置:首页 > 开源系统 > drupal的weight

    drupal的weight


    时间:2014-06-19 20:48:45 来源:51xuejianzhan.com 作者:网络 点击:73
    In Drupal, the order in which a module's hooks get called is dependent on the weight of your module in the system table. You can set a low weight (including negative numbers) to get your module to execute before others. Or, you can set a high weight to execute after other modules.
    意味着我们采用低的数字,会被优先执行 0 比1 先执行。
     
    If no weight is defined modules get a default weight of 0.
     
    To find out the order in which the modules are executed you can look in the system table or use the the module_list() function:
     
    $modules = implode(', ', module_list());
    print $modules;
    Variable weight per hook
     
    In Drupal 7, modules can vary the weights of their hooks to be more flexible. For details, see hook_module_implements_alter() in the API documentation.
     
    Code to update weight
     
    You will want to modify and then place this code into your module's modulename.install file in an implementation of hook_install (i.e. within a [your_module_name]_install function).
     
    <?php
    db_query("UPDATE {system} SET weight = [your_preferred_weight] WHERE type = 'module' AND name = '[your_module_name]'");
    ?>
    In Drupal 7
     
    <?php
    function your_module_name_install() {
      db_update('system')
        ->fields(array('weight' => your_preferred_weight))
        ->condition('name', '[your_module_name]', '=')
        ->execute();
    }
    ?>
    If you want your module's weight to be 1 higher than another module's, you can use the following code:
     
    <?php
    // Find out the weight of the other module
    $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = '[the_other_module_name]'"));
    // Set our module to a weight 1 higher
    db_query("UPDATE {system} SET weight = %d WHERE name = '[your_module_name]'", $weight + 1);
    ?>
    For Drupal 7 this code is as follows:
     
    <?php
      $weight = db_select('system', 's')
                  ->fields('s', array('weight'))
                  ->condition('name', '[the_other_module_name]', '=')
                  ->execute()
                  ->fetchField();
      db_update('system')
        ->fields(array('weight' => $weight +1))
        ->condition('name', '[your_module_name]', '=')
        ->execute();
    ?>
    Utility module
     
    You can also use the Utility module for an admin interface to change weights of modules installed on your site.
     
    Example module weights
     
    Find below an excerpt from the system database table that shows the weight of common core and contributed modules. Core modules all use a weight of zero.
     
    +----------------------------+--------+--------+--------+
    | name                       | type   | status | weight |
    +----------------------------+--------+--------+--------+
    | strongarm                  | module |      1 |  -1000 |
    | block                      | module |      1 |     -5 |
    | webform                    | module |      1 |     -1 |
    | acquia_search              | module |      1 |      0 |
    | backup_migrate             | module |      1 |      0 |
    | colorbox                   | module |      1 |      0 |
    | contextual                 | module |      1 |      0 |
    | crumbs                     | module |      1 |      0 |
    | ctools                     | module |      1 |      0 |
    学建站51xuejianzhan.com
    | date                       | module |      1 |      0 |
    | date_api                   | module |      1 |      0 |
    | date_views                 | module |      1 |      0 |
    | entity                     | module |      1 |      0 |
    | faq                        | module |      1 |      0 |
    | field                      | module |      1 |      0 |
    | field_ui                   | module |      1 |      0 |
    | file                       | module |      1 |      0 |
    | filter                     | module |      1 |      0 |
    | geocoder                   | module |      1 |      0 |
    | geofield                   | module |      1 |      0 |
    | geophp                     | module |      1 |      0 |
    | image                      | module |      1 |      0 |
    | libraries                  | module |      1 |      0 |
    | link                       | module |      1 |      0 |
    | list                       | module |      1 |      0 |
    | locale                     | module |      1 |      0 |
    | masquerade                 | module |      1 |      0 |
    | menu                       | module |      1 |      0 |
    | menu_block                 | module |      1 |      0 |
    | node                       | module |      1 |      0 |
    | options                    | module |      1 |      0 |
    | path                       | module |      1 |      0 |
    | plupload                   | module |      1 |      0 |
    | print                      | module |      1 |      0 |
    | search                     | module |      1 |      0 |
    | shortcut                   | module |      1 |      0 |
    | taxonomy                   | module |      1 |      0 |
    | taxonomy_manager           | module |      1 |      0 |
    | text                       | module |      1 |      0 |
    | token                      | module |      1 |      0 |
    | translation                | module |      1 |      0 |
    | transliteration            | module |      1 |      0 |
    | update                     | module |      1 |      0 |
    | user                       | module |      1 |      0 |
    | views_ui                   | module |      1 |      0 |
    | wysiwyg                    | module |      1 |      0 |
    | dblog                      | module |      1 |      0 |
    | domain                     | module |      1 |      0 |
    | mollom                     | module |      1 |      0 |
    | overlay                    | module |      1 |      0 |
    | system                     | module |      1 |      0 |
    | acquia_agent               | module |      1 |      0 |
    | ckeditor_link              | module |      1 |      1 |
    | ds                         | module |      1 |      1 |
    | field_group                | module |      1 |      1 |
    | pathauto                   | module |      1 |      1 |
    | i18n                       | module |      1 |     10 |
    | i18n_string                | module |      1 |     10 |
    | views                      | module |      1 |     10 |
    | rules                      | module |      1 |     20 |
    | admin_menu                 | module |      1 |    100 |
    +----------------------------+--------+--------+--------+
    Updating the weight of existing modules
     
    A common situation is that you may need to change the weight of an existing module you have installed on your site. You should firstly disable your module(admin>modules or drush dis my_module_name) then uninstall your module (admin>modules>uninstall or drush pm-uninstall my_module_name). Once you have added your .install file you can then enable your module(admin>modules or drush en my_module_name) which will fire your hook_install function and update the weight in the system table.
     
    Changing weight using a hook_update_N implementation
     
    Specially useful when you want this inside a hook_update_N() implementation, for example:
     
    <?php
    /**
     * Set weight of the My Funky Module module to 13
     */
    function my_funky_module_update_7100() {
        db_update('system')
        ->fields(array('weight' => 13))
        ->condition('name', 'my_funky_module', '=')
        ->execute();
    ?>
    学建站51xuejianzhan.com
    Changing module weight via UI
     
    For an admin interface for altering the module weights in D7 try the modules_weight module as util module only does it for D6

    (责任编辑:小站童)
    weight, drupal, 函数,
    评论

    用户名 验证码
    最新评论
    赞助商链接
    网页取色器 | 网页配色工具 | 时间转换 | 精彩收藏 | 每日阅读 | 常用函数库 |

    Copyright © 2012 - 2013 我要学建站 All rights reserved.