8 use Drupal\Core\Extension\Extension;
11 * Implements hook_system_info_alter().
13 * Manipulate module dependencies to test dependency chains.
15 function module_test_system_info_alter(&$info, Extension $file, $type) {
16 if (\Drupal::state()->get('module_test.dependency') == 'missing dependency') {
17 if ($file->getName() == 'color') {
18 // Make color module depend on config.
19 $info['dependencies'][] = 'config';
21 elseif ($file->getName() == 'config') {
22 // Make config module depend on a non-existing module.
23 $info['dependencies'][] = 'foo';
26 elseif (\Drupal::state()->get('module_test.dependency') == 'dependency') {
27 if ($file->getName() == 'color') {
28 // Make color module depend on config.
29 $info['dependencies'][] = 'config';
31 elseif ($file->getName() == 'config') {
32 // Make config module depend on help module.
33 $info['dependencies'][] = 'help';
35 elseif ($file->getName() == 'entity_test') {
36 // Make entity test module depend on help module.
37 $info['dependencies'][] = 'help';
40 elseif (\Drupal::state()->get('module_test.dependency') == 'version dependency') {
41 if ($file->getName() == 'color') {
42 // Make color module depend on config.
43 $info['dependencies'][] = 'config';
45 elseif ($file->getName() == 'config') {
46 // Make config module depend on a specific version of help module.
47 $info['dependencies'][] = 'help (1.x)';
49 elseif ($file->getName() == 'help') {
50 // Set help module to a version compatible with the above.
51 $info['version'] = '8.x-1.0';
54 if ($file->getName() == 'seven' && $type == 'theme') {
55 $info['regions']['test_region'] = 'Test region';
60 * Implements hook_hook_info().
62 function module_test_hook_info() {
63 $hooks['test_hook'] = [
70 * Load function used by module_test_hook_dynamic_loading_invoke_all_during_load().
72 * @see module_test_menu()
74 function module_test_load($param) {
75 $result = \Drupal::moduleHandler()->invokeAll('test_hook');
76 return $result[$param];
80 * Implements hook_modules_installed().
82 function module_test_modules_installed($modules) {
83 // Record the ordered list of modules that were passed in to this hook so we
84 // can check that the modules were enabled in the correct sequence.
85 \Drupal::state()->set('module_test.install_order', $modules);
89 * Implements hook_modules_uninstalled().
91 function module_test_modules_uninstalled($modules) {
92 // Record the ordered list of modules that were passed in to this hook so we
93 // can check that the modules were uninstalled in the correct sequence.
94 \Drupal::state()->set('module_test.uninstall_order', $modules);
98 * Implements hook_module_implements_alter()
100 * @see module_test_altered_test_hook()
101 * @see \Drupal\system\Tests\Module\ModuleImplementsAlterTest::testModuleImplementsAlter()
103 function module_test_module_implements_alter(&$implementations, $hook) {
104 if ($hook === 'altered_test_hook') {
105 // Add a hook implementation, that will be found in
106 // module_test.implementation.inc.
107 $implementations['module_test'] = 'implementations';
109 if ($hook === 'unimplemented_test_hook') {
110 // Add the non-existing function module_test_unimplemented_test_hook(). This
111 // should cause an exception to be thrown in
112 // \Drupal\Core\Extension\ModuleHandler::buildImplementationInfo('unimplemented_test_hook').
113 $implementations['module_test'] = FALSE;