Commit b3f9bc77 authored by Dries's avatar Dries

- Patch #1617208 by effulgentsia, neclimdul: after kernel patch,...

- Patch #1617208 by effulgentsia, neclimdul: after kernel patch, module_hook_info() returns an empty array when called by load callback, access callback, or hook_init().
parent 57ab8a54
......@@ -760,11 +760,12 @@ function module_implements_reset() {
* Retrieve a list of what hooks are explicitly declared.
*/
function module_hook_info() {
// This function is indirectly invoked from bootstrap_invoke_all(), in which
// case common.inc, subsystems, and modules are not loaded yet, so it does not
// make sense to support hook groups resp. lazy-loaded include files prior to
// full bootstrap.
if (drupal_bootstrap(NULL, FALSE) != DRUPAL_BOOTSTRAP_FULL) {
// When this function is indirectly invoked from bootstrap_invoke_all() prior
// to all modules being loaded, we do not want to cache an incomplete
// hook_hook_info() result, so instead return an empty array. This requires
// bootstrap hook implementations to reside in the .module file, which is
// optimal for performance anyway.
if (!module_load_all(NULL)) {
return array();
}
$hook_info = &drupal_static(__FUNCTION__);
......
......@@ -137,6 +137,19 @@ function testModuleInvokeAll() {
$this->assertText('success!', t('module_invoke_all() dynamically loads a hook defined in hook_hook_info().'));
}
/**
* Test that a menu item load function can invoke hooks defined in hook_hook_info().
*
* We test this separately from testModuleInvokeAll(), because menu item load
* functions execute early in the request handling.
*/
function testModuleInvokeAllDuringLoadFunction() {
module_enable(array('module_test'), FALSE);
$this->resetAll();
$this->drupalGet('module-test/hook-dynamic-loading-invoke-all-during-load/module_test');
$this->assertText('success!', t('Menu item load function invokes a hook defined in hook_hook_info().'));
}
/**
* Test dependency resolution.
*/
......
......@@ -78,6 +78,12 @@ function module_test_menu() {
'page callback' => 'module_test_hook_dynamic_loading_invoke_all',
'access arguments' => array('access content'),
);
$items['module-test/hook-dynamic-loading-invoke-all-during-load/%module_test'] = array(
'title' => 'Test hook dynamic loading (menu item load)',
'page callback' => 'module_test_hook_dynamic_loading_invoke_all_during_load',
'page arguments' => array(2),
'access arguments' => array('access content'),
);
$items['module-test/class-loading'] = array(
'title' => 'Test loading a class from another module',
'page callback' => 'module_test_class_loading',
......@@ -108,6 +114,26 @@ function module_test_hook_dynamic_loading_invoke_all() {
return $result['module_test'];
}
/**
* Page callback for 'hook dynamic loading' test.
*
* If the hook is dynamically loaded correctly, the menu callback should
* return 'success!'.
*/
function module_test_hook_dynamic_loading_invoke_all_during_load($param) {
return $param;
}
/**
* Load function used by module_test_hook_dynamic_loading_invoke_all_during_load().
*
* @see module_test_menu().
*/
function module_test_load($param) {
$result = module_invoke_all('test_hook');
return $result[$param];
}
/**
* Page callback for 'class loading' test.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment