如何在 drupal 8 中使用 module_set_weight 函数?
how to use module_set_weight function in drupal 8?
在module_set_weight($module, $weight)
函数中,权重参数的表示是什么?
数字越大,模块的执行顺序越低?谁能给我举个例子吗?
int $weight: An integer representing the weight of the module.
在 Drupal 中,模块的 权重 将决定挂钩函数(在它们中实现)的执行顺序。重量较小的将首先执行。对于同等权重的模块,将使用模块名称的字母顺序。
比如我们有module_a
(weight=0)和module_b
(weight=1),它们里面都有hook_entity_update
的实现:
module_a.module
function module_a_entity_update($entity) {
// some logic
}
module_b.module
function module_b_entity_update($entity) {
// some logic
}
所以当调用hook_entity_update
钩子函数时,module_a_entity_update()
会先于module_b_entity_update()
执行。
在module_set_weight($module, $weight)
函数中,权重参数的表示是什么?
数字越大,模块的执行顺序越低?谁能给我举个例子吗?
int $weight: An integer representing the weight of the module.
在 Drupal 中,模块的 权重 将决定挂钩函数(在它们中实现)的执行顺序。重量较小的将首先执行。对于同等权重的模块,将使用模块名称的字母顺序。
比如我们有module_a
(weight=0)和module_b
(weight=1),它们里面都有hook_entity_update
的实现:
module_a.module
function module_a_entity_update($entity) {
// some logic
}
module_b.module
function module_b_entity_update($entity) {
// some logic
}
所以当调用hook_entity_update
钩子函数时,module_a_entity_update()
会先于module_b_entity_update()
执行。