Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / modules / system_test / system_test.module
1 <?php
2
3 /**
4  * @file
5  * Test module.
6  */
7
8 use Drupal\Core\Extension\Extension;
9 use Drupal\Core\Routing\RouteMatchInterface;
10
11 /**
12  * Implements hook_help().
13  */
14 function system_test_help($route_name, RouteMatchInterface $route_match) {
15   switch ($route_name) {
16     case 'help.page.system_test':
17       $output = '';
18       $output .= '<h3>' . t('Test Help Page') . '</h3>';
19       $output .= '<p>' . t('This is a test help page for the system_test module for the purpose of testing if the "Help" link displays properly.') . '</p>';
20       return $output;
21   }
22 }
23
24 /**
25  * Implements hook_modules_installed().
26  */
27 function system_test_modules_installed($modules) {
28   if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
29     foreach ($modules as $module) {
30       \Drupal::messenger()->addStatus(t('hook_modules_installed fired for @module', ['@module' => $module]));
31     }
32   }
33 }
34
35 /**
36  * Implements hook_modules_uninstalled().
37  */
38 function system_test_modules_uninstalled($modules) {
39   if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
40     foreach ($modules as $module) {
41       \Drupal::messenger()->addStatus(t('hook_modules_uninstalled fired for @module', ['@module' => $module]));
42     }
43   }
44 }
45
46 /**
47  * Implements hook_system_info_alter().
48  */
49 function system_test_system_info_alter(&$info, Extension $file, $type) {
50   // We need a static otherwise the last test will fail to alter common_test.
51   static $test;
52   if (($dependencies = \Drupal::state()->get('system_test.dependencies')) || $test) {
53     if ($file->getName() == 'module_test') {
54       $info['hidden'] = FALSE;
55       $info['dependencies'][] = array_shift($dependencies);
56       \Drupal::state()->set('system_test.dependencies', $dependencies);
57       $test = TRUE;
58     }
59     if ($file->getName() == 'common_test') {
60       $info['hidden'] = FALSE;
61       $info['version'] = '8.x-2.4-beta3';
62     }
63   }
64
65   // Make the system_dependencies_test visible by default.
66   if ($file->getName() == 'system_dependencies_test') {
67     $info['hidden'] = FALSE;
68   }
69   if (in_array($file->getName(), [
70     'system_incompatible_module_version_dependencies_test',
71     'system_incompatible_core_version_dependencies_test',
72     'system_incompatible_module_version_test',
73     'system_incompatible_core_version_test',
74   ])) {
75     $info['hidden'] = FALSE;
76   }
77   if ($file->getName() == 'requirements1_test' || $file->getName() == 'requirements2_test') {
78     $info['hidden'] = FALSE;
79   }
80   if ($file->getName() == 'system_test') {
81     $info['hidden'] = \Drupal::state()->get('system_test.module_hidden', TRUE);
82   }
83 }
84
85 /**
86  * Implements hook_page_attachments().
87  */
88 function system_test_page_attachments(array &$page) {
89   // Used by FrontPageTestCase to get the results of
90   // \Drupal::service('path.matcher')->isFrontPage().
91   $frontpage = \Drupal::state()->get('system_test.front_page_output') ?: 0;
92   if ($frontpage && \Drupal::service('path.matcher')->isFrontPage()) {
93     \Drupal::messenger()->addStatus(t('On front page.'));
94   }
95 }
96
97 /**
98  * Dummy shutdown function which registers another shutdown function.
99  */
100 function _system_test_first_shutdown_function($arg1, $arg2) {
101   // Set something to ensure that this function got called.
102   \Drupal::state()->set('_system_test_first_shutdown_function', [$arg1, $arg2]);
103   drupal_register_shutdown_function('_system_test_second_shutdown_function', $arg1, $arg2);
104 }
105
106 /**
107  * Dummy shutdown function.
108  */
109 function _system_test_second_shutdown_function($arg1, $arg2) {
110   // Set something to ensure that this function got called.
111   \Drupal::state()->set('_system_test_second_shutdown_function', [$arg1, $arg2]);
112
113   // Throw an exception with an HTML tag. Since this is called in a shutdown
114   // function, it will not bubble up to the default exception handler but will
115   // be caught in _drupal_shutdown_function() and be displayed through
116   // \Drupal\Core\Utility\Error::renderExceptionSafe() if possible.
117   throw new Exception('Drupal is <blink>awesome</blink>.');
118 }
119
120 /**
121  * Implements hook_filetransfer_info().
122  */
123 function system_test_filetransfer_info() {
124   return [
125     'system_test' => [
126       'title' => t('System Test FileTransfer'),
127       'class' => 'Drupal\system_test\MockFileTransfer',
128       'weight' => -10,
129     ],
130   ];
131 }
132
133 /**
134  * Implements hook_module_preinstall().
135  */
136 function system_test_module_preinstall($module) {
137   \Drupal::state()->set('system_test_preinstall_module', $module);
138 }
139
140 /**
141  * Implements hook_module_preuninstall().
142  */
143 function system_test_module_preuninstall($module) {
144   \Drupal::state()->set('system_test_preuninstall_module', $module);
145 }