summaryrefslogtreecommitdiffstats
path: root/core/modules/system/tests/modules/module_test/module_test.module
blob: ff7af5742ba0f81297b14a8eb5256b259392083c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php

use Drupal\Core\Extension\Extension;

/**
 * Implements hook_system_info_alter().
 *
 * Manipulate module dependencies to test dependency chains.
 */
function module_test_system_info_alter(&$info, Extension $file, $type) {
  if (\Drupal::state()->get('module_test.dependency') == 'missing dependency') {
    if ($file->getName() == 'color') {
      // Make color module depend on config.
      $info['dependencies'][] = 'config';
    }
    elseif ($file->getName() == 'config') {
      // Make config module depend on a non-existing module.
      $info['dependencies'][] = 'foo';
    }
  }
  elseif (\Drupal::state()->get('module_test.dependency') == 'dependency') {
    if ($file->getName() == 'color') {
      // Make color module depend on config.
      $info['dependencies'][] = 'config';
    }
    elseif ($file->getName() == 'config') {
      // Make config module depend on help module.
      $info['dependencies'][] = 'help';
    }
    elseif ($file->getName() == 'entity_test') {
      // Make entity test module depend on help module.
      $info['dependencies'][] = 'help';
    }
  }
  elseif (\Drupal::state()->get('module_test.dependency') == 'version dependency') {
    if ($file->getName() == 'color') {
      // Make color module depend on config.
      $info['dependencies'][] = 'config';
    }
    elseif ($file->getName() == 'config') {
      // Make config module depend on a specific version of help module.
      $info['dependencies'][] = 'help (1.x)';
    }
    elseif ($file->getName() == 'help') {
      // Set help module to a version compatible with the above.
      $info['version'] = '8.x-1.0';
    }
  }
  if ($file->getName() == 'seven' && $type == 'theme') {
    $info['regions']['test_region'] = 'Test region';
  }
}

/**
 * Implements hook_hook_info().
 */
function module_test_hook_info() {
  $hooks['test_hook'] = array(
    'group' => 'file',
  );
  return $hooks;
}

/**
 * Page callback for 'hook dynamic loading' test.
 *
 * If the hook is dynamically loaded correctly, the menu callback should
 * return 'success!'.
 *
 * @deprecated \Drupal\module_test\Controller\ModuleTestController::hookDynamicLoadingInvoke()
 */
function module_test_hook_dynamic_loading_invoke() {
  $result = \Drupal::moduleHandler()->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!'.
 *
 * @deprecated \Drupal\module_test\Controller\ModuleTestController::hookDynamicLoadingInvokeAll()
 */
function module_test_hook_dynamic_loading_invoke_all() {
  $result = \Drupal::moduleHandler()->invokeAll('test_hook');
  return $result['module_test'];
}

/**
 * Load function used by module_test_hook_dynamic_loading_invoke_all_during_load().
 *
 * @see module_test_menu().
 */
function module_test_load($param) {
  $result = \Drupal::moduleHandler()->invokeAll('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.
 *
 * @deprecated \Drupal\module_test\Controller\ModuleTestController::testClassLoading()
 */
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_installed().
 */
function module_test_modules_installed($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.
  \Drupal::state()->set('module_test.install_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.
  \Drupal::state()->set('module_test.uninstall_order', $modules);
}

/**
 * Implements hook_module_implements_alter()
 *
 * @see module_test_altered_test_hook()
 * @see \Drupal\system\Tests\Module\ModuleImplementsAlterTest::testModuleImplementsAlter()
 */
function module_test_module_implements_alter(&$implementations, $hook) {
  if ($hook === 'altered_test_hook') {
    // Add a hook implementation, that will be found in
    // module_test.implementation.inc.
    $implementations['module_test'] = 'implementations';
  }
  if ($hook === 'unimplemented_test_hook') {
    // Add the non-existing function module_test_unimplemented_test_hook(). This
    // should cause an exception to be thrown in
    // \Drupal\Core\Extension\ModuleHandler::buildImplementationInfo('unimplemented_test_hook').
    $implementations['module_test'] = FALSE;
  }
}