8 use Drupal\Core\Extension\Extension;
9 use Drupal\Core\Routing\RouteMatchInterface;
12 * Implements hook_help().
14 function system_test_help($route_name, RouteMatchInterface $route_match) {
15 switch ($route_name) {
16 case 'help.page.system_test':
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>';
25 * Implements hook_modules_installed().
27 function system_test_modules_installed($modules) {
28 if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
29 foreach ($modules as $module) {
30 drupal_set_message(t('hook_modules_installed fired for @module', ['@module' => $module]));
36 * Implements hook_modules_uninstalled().
38 function system_test_modules_uninstalled($modules) {
39 if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
40 foreach ($modules as $module) {
41 drupal_set_message(t('hook_modules_uninstalled fired for @module', ['@module' => $module]));
47 * Implements hook_system_info_alter().
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.
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);
59 if ($file->getName() == 'common_test') {
60 $info['hidden'] = FALSE;
61 $info['version'] = '8.x-2.4-beta3';
65 // Make the system_dependencies_test visible by default.
66 if ($file->getName() == 'system_dependencies_test') {
67 $info['hidden'] = FALSE;
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',
75 $info['hidden'] = FALSE;
77 if ($file->getName() == 'requirements1_test' || $file->getName() == 'requirements2_test') {
78 $info['hidden'] = FALSE;
80 if ($file->getName() == 'system_test') {
81 $info['hidden'] = \Drupal::state()->get('system_test.module_hidden', TRUE);
86 * Implements hook_page_attachments().
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_set_message(t('On front page.'));
98 * Dummy shutdown function which registers another shutdown function.
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);
107 * Dummy shutdown function.
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]);
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>.');
121 * Implements hook_filetransfer_info().
123 function system_test_filetransfer_info() {
126 'title' => t('System Test FileTransfer'),
127 'class' => 'Drupal\system_test\MockFileTransfer',
134 * Implements hook_module_preinstall().
136 function system_test_module_preinstall($module) {
137 \Drupal::state()->set('system_test_preinstall_module', $module);
141 * Implements hook_module_preuninstall().
143 function system_test_module_preuninstall($module) {
144 \Drupal::state()->set('system_test_preuninstall_module', $module);