dba4889d53050b6161d034f39217d8744d17a0a4
[yaffs-website] / module_test / module_test.module
1 <?php
2
3 /**
4  * @file
5  * Test module.
6  */
7
8 use Drupal\Core\Extension\Extension;
9
10 /**
11  * Implements hook_system_info_alter().
12  *
13  * Manipulate module dependencies to test dependency chains.
14  */
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';
20     }
21     elseif ($file->getName() == 'config') {
22       // Make config module depend on a non-existing module.
23       $info['dependencies'][] = 'foo';
24     }
25   }
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';
30     }
31     elseif ($file->getName() == 'config') {
32       // Make config module depend on help module.
33       $info['dependencies'][] = 'help';
34     }
35     elseif ($file->getName() == 'entity_test') {
36       // Make entity test module depend on help module.
37       $info['dependencies'][] = 'help';
38     }
39   }
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';
44     }
45     elseif ($file->getName() == 'config') {
46       // Make config module depend on a specific version of help module.
47       $info['dependencies'][] = 'help (1.x)';
48     }
49     elseif ($file->getName() == 'help') {
50       // Set help module to a version compatible with the above.
51       $info['version'] = '8.x-1.0';
52     }
53   }
54   if ($file->getName() == 'seven' && $type == 'theme') {
55     $info['regions']['test_region'] = 'Test region';
56   }
57 }
58
59 /**
60  * Implements hook_hook_info().
61  */
62 function module_test_hook_info() {
63   $hooks['test_hook'] = [
64     'group' => 'file',
65   ];
66   return $hooks;
67 }
68
69 /**
70  * Load function used by module_test_hook_dynamic_loading_invoke_all_during_load().
71  *
72  * @see module_test_menu()
73  */
74 function module_test_load($param) {
75   $result = \Drupal::moduleHandler()->invokeAll('test_hook');
76   return $result[$param];
77 }
78
79 /**
80  * Implements hook_modules_installed().
81  */
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);
86 }
87
88 /**
89  * Implements hook_modules_uninstalled().
90  */
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);
95 }
96
97 /**
98  * Implements hook_module_implements_alter()
99  *
100  * @see module_test_altered_test_hook()
101  * @see \Drupal\system\Tests\Module\ModuleImplementsAlterTest::testModuleImplementsAlter()
102  */
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';
108   }
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;
114   }
115 }