system_test.module 3.96 KB
Newer Older
1 2
<?php

3
use Drupal\Core\Extension\Extension;
4

5
/**
6
 * Implements hook_modules_installed().
7 8
 */
function system_test_modules_installed($modules) {
9
  if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
10 11 12
    foreach ($modules as $module) {
      drupal_set_message(t('hook_modules_installed fired for @module', array('@module' => $module)));
    }
13 14 15 16
  }
}

/**
17
 * Implements hook_modules_uninstalled().
18 19
 */
function system_test_modules_uninstalled($modules) {
20
  if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
21 22 23
    foreach ($modules as $module) {
      drupal_set_message(t('hook_modules_uninstalled fired for @module', array('@module' => $module)));
    }
24 25
  }
}
26

27
/**
28
 * Implements hook_system_info_alter().
29
 */
30
function system_test_system_info_alter(&$info, Extension $file, $type) {
31 32
  // We need a static otherwise the last test will fail to alter common_test.
  static $test;
33
  if (($dependencies = \Drupal::state()->get('system_test.dependencies')) || $test) {
34
    if ($file->getName() == 'module_test') {
35 36
      $info['hidden'] = FALSE;
      $info['dependencies'][] = array_shift($dependencies);
37
      \Drupal::state()->set('system_test.dependencies', $dependencies);
38 39
      $test = TRUE;
    }
40
    if ($file->getName() == 'common_test') {
41
      $info['hidden'] = FALSE;
42
      $info['version'] = '8.x-2.4-beta3';
43 44
    }
  }
45 46

  // Make the system_dependencies_test visible by default.
47
  if ($file->getName() == 'system_dependencies_test') {
48 49
    $info['hidden'] = FALSE;
  }
50
  if (in_array($file->getName(), array(
51 52 53 54 55 56 57
    'system_incompatible_module_version_dependencies_test',
    'system_incompatible_core_version_dependencies_test',
    'system_incompatible_module_version_test',
    'system_incompatible_core_version_test',
  ))) {
    $info['hidden'] = FALSE;
  }
58
  if ($file->getName() == 'requirements1_test' || $file->getName() == 'requirements2_test') {
59 60
    $info['hidden'] = FALSE;
  }
61 62 63
  if ($file->getName() == 'system_test') {
    $info['hidden'] = \Drupal::state()->get('system_test.module_hidden', TRUE);
  }
64 65
}

66
/**
67
 * Implements hook_page_attachments().
68
 */
69
function system_test_page_attachments(array &$page) {
70 71
  // Used by FrontPageTestCase to get the results of
  // \Drupal::service('path.matcher')->isFrontPage().
72
  $frontpage = \Drupal::state()->get('system_test.front_page_output') ?: 0;
73
  if ($frontpage && \Drupal::service('path.matcher')->isFrontPage()) {
74 75
    drupal_set_message(t('On front page.'));
  }
76 77
}

78 79 80 81
/**
 * Dummy shutdown function which registers another shutdown function.
 */
function _system_test_first_shutdown_function($arg1, $arg2) {
82 83
  // Set something to ensure that this function got called.
  \Drupal::state()->set('_system_test_first_shutdown_function', array($arg1, $arg2));
84 85 86 87 88 89 90
  drupal_register_shutdown_function('_system_test_second_shutdown_function', $arg1, $arg2);
}

/**
 * Dummy shutdown function.
 */
function _system_test_second_shutdown_function($arg1, $arg2) {
91 92
  // Set something to ensure that this function got called.
  \Drupal::state()->set('_system_test_second_shutdown_function', array($arg1, $arg2));
93 94 95

  // Throw an exception with an HTML tag. Since this is called in a shutdown
  // function, it will not bubble up to the default exception handler but will
96
  // be caught in _drupal_shutdown_function() and be displayed through
97
  // \Drupal\Core\Utility\Error::renderExceptionSafe() if possible.
98
  throw new Exception('Drupal is <blink>awesome</blink>.');
99 100
}

101 102 103 104 105 106 107
/**
 * Implements hook_filetransfer_info().
 */
function system_test_filetransfer_info() {
  return array(
    'system_test' => array(
      'title' => t('System Test FileTransfer'),
108
      'class' => 'Drupal\system_test\MockFileTransfer',
109 110 111 112 113
      'weight' => -10,
    ),
  );
}

114 115 116 117
/**
 * Implements hook_module_preinstall().
 */
function system_test_module_preinstall($module) {
118
  \Drupal::state()->set('system_test_preinstall_module', $module);
119 120 121 122 123 124
}

/**
 * Implements hook_module_preuninstall().
 */
function system_test_module_preuninstall($module) {
125
  \Drupal::state()->set('system_test_preuninstall_module', $module);
126
}