<?php
/**
* Implements hook_permission().
*/
function module_test_permission() {
return array(
'module_test perm' => t('example perm for module_test module'),
);
}
/**
* Implements hook_system_info_alter().
*
* Manipulate module dependencies to test dependency chains.
*/
function module_test_system_info_alter(&$info, $file, $type) {
if (state()
->get('module_test.dependency') == 'missing dependency') {
if ($file->name == 'forum') {
// Make forum module depend on poll.
$info['dependencies'][] = 'poll';
}
elseif ($file->name == 'poll') {
// Make poll depend on a made-up module.
$info['dependencies'][] = 'foo';
}
}
elseif (state()
->get('module_test.dependency') == 'dependency') {
if ($file->name == 'forum') {
// Make the forum module depend on poll.
$info['dependencies'][] = 'poll';
}
elseif ($file->name == 'poll') {
// Make poll depend on php module.
$info['dependencies'][] = 'php';
}
}
elseif (state()
->get('module_test.dependency') == 'version dependency') {
if ($file->name == 'forum') {
// Make the forum module depend on poll.
$info['dependencies'][] = 'poll';
}
elseif ($file->name == 'poll') {
// Make poll depend on a specific version of php module.
$info['dependencies'][] = 'php (1.x)';
}
elseif ($file->name == 'php') {
// Set php module to a version compatible with the above.
$info['version'] = '8.x-1.0';
}
}
if ($file->name == 'seven' && $type == 'theme') {
$info['regions']['test_region'] = t('Test region');
}
}
/**
* Implements hook_hook_info().
*/
function module_test_hook_info() {
$hooks['test_hook'] = array(
'group' => 'file',
);
return $hooks;
}
/**
* Implements hook_menu().
*/
function module_test_menu() {
$items['module-test/hook-dynamic-loading-invoke'] = array(
'title' => 'Test hook dynamic loading (invoke)',
'page callback' => 'module_test_hook_dynamic_loading_invoke',
'access arguments' => array(
'access content',
),
);
$items['module-test/hook-dynamic-loading-invoke-all'] = array(
'title' => 'Test hook dynamic loading (invoke_all)',
'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',
'access callback' => TRUE,
);
return $items;
}
/**
* 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() {
$result = module_invoke('module_test', 'test_hook');
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() {
$result = module_invoke_all('test_hook');
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.
*
* This module does not have a dependency on module_autoload_test.module. If
* that module is enabled, this function should return the string
* 'Drupal\\module_autoload_test\\SomeClass::testMethod() was invoked.'. If
* that module is not enabled, this function should return nothing.
*/
function module_test_class_loading() {
if (class_exists('Drupal\\module_autoload_test\\SomeClass')) {
$obj = new Drupal\module_autoload_test\SomeClass();
return $obj
->testMethod();
}
}
/**
* Implements hook_modules_enabled().
*/
function module_test_modules_enabled($modules) {
// Record the ordered list of modules that were passed in to this hook so we
// can check that the modules were enabled in the correct sequence.
state()
->set('system_test.module_enable_order', $modules);
}
/**
* Implements hook_modules_disabled().
*/
function module_test_modules_disabled($modules) {
// Record the ordered list of modules that were passed in to this hook so we
// can check that the modules were disabled in the correct sequence.
variable_set('test_module_disable_order', $modules);
}
/**
* Implements hook_modules_uninstalled().
*/
function module_test_modules_uninstalled($modules) {
// Record the ordered list of modules that were passed in to this hook so we
// can check that the modules were uninstalled in the correct sequence.
variable_set('test_module_uninstall_order', $modules);
}
Name | Description |
---|---|
module_test_class_loading | Page callback for 'class loading' test. |
module_test_hook_dynamic_loading_invoke | Page callback for 'hook dynamic loading' test. |
module_test_hook_dynamic_loading_invoke_all | Page callback for 'hook dynamic loading' test. |
module_test_hook_dynamic_loading_invoke_all_during_load | Page callback for 'hook dynamic loading' test. |
module_test_hook_info | Implements hook_hook_info(). |
module_test_load | Load function used by module_test_hook_dynamic_loading_invoke_all_during_load(). |
module_test_menu | Implements hook_menu(). |
module_test_modules_disabled | Implements hook_modules_disabled(). |
module_test_modules_enabled | Implements hook_modules_enabled(). |
module_test_modules_uninstalled | Implements hook_modules_uninstalled(). |
module_test_permission | Implements hook_permission(). |
module_test_system_info_alter | Implements hook_system_info_alter(). |