在Drupal.org API上,我注意到Drupal 8没有记录hook_init()。在更改记录中,我发现Bootstrap钩子不再存在,它指向摆脱所有'bootstrap'钩子,而Bootstrap钩子在这里据说是hook_boot()和hook_exit(); 什么也没说hook_init()。
我在Drupal 8源代码中搜索hook_init,发现以下代码。第一个是hook_init()在评论中提及的内容;其他两个似乎是一个hook_init()实现,但是它们都得到了我不期望的参数。
function overlay_enable() {
if (strpos(current_path(), 'admin/modules') === 0) {
// Flag for a redirect to <front>#overlay=admin/modules on hook_init().
$_SESSION['overlay_enable_redirect'] = 1;
}
}
/**
* Implements hook_init().
*/
function phptemplate_init($template) {
$file = dirname($template->filename) . '/' . $template->name . '.theme';
if (file_exists($file)) {
include_once DRUPAL_ROOT . '/' . $file;
}
}
/**
* Implements hook_init().
*/
function twig_init($template) {
$file = dirname($template->filename) . '/' . $template->name . '.theme';
if (file_exists($file)) {
include_once DRUPAL_ROOT . '/' . $file;
}
}
我还寻找了调用任何函数,hook_init()但没有找到任何函数。
是hook_init()仍然在Drupal 8中使用?如果不再使用它,如何转换Drupal 7代码实现hook_init()?