Drupal 执行它的 _cron 钩子的顺序是怎样的?这对我正在开发的某个定制模块非常重要,但在网上似乎找不到任何相关文档。也许我搜索的关键词不对!
对于Drupal 8,您需要在hook_module_implements_alter
中重新排列模块的实现顺序:
function YOUR_MODULE_module_implements_alter(&$implementations, $hook) {
// Move our hook_cron() implementation to the end of the list.
if ($hook == 'cron') {
$group = $implementations['YOUR_MODULE'];
unset($implementations['YOUR_MODULE']);
$implementations['YOUR_MODULE'] = $group;
}
}
hook_cron
:function YOUR_MODULE_module_implements_alter(&$implementations, $hook) {
// Move our hook_cron() implementation to the top of the list.
if ($hook == 'cron') {
$group = $implementations['YOUR_MODULE'];
$implementations = [
'YOUR_MODULE' => $group,
] + $implementations;
}
}
钩子的执行顺序由实现它们的模块的权重决定;权重较大的模块将最后执行。