locale_test.module 2.88 KB
Newer Older
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Mock module for locale layer tests.
 */

8
/**
9 10
 * Implements hook_boot().
 *
11 12 13 14 15 16 17 18
 * For testing domain language negotiation, we fake it by setting
 * the HTTP_HOST here
 */
function locale_test_boot() {
  if (variable_get('locale_test_domain')) {
    $_SERVER['HTTP_HOST'] = variable_get('locale_test_domain');
  }
}
19

20 21 22 23 24
/**
 * Implements hook_init().
 */
function locale_test_init() {
  locale_test_store_language_negotiation();
25 26
  if (isset($GLOBALS['language_interface']) && isset($GLOBALS['language_interface']->method_id)) {
    drupal_set_message(t('Language negotiation method: @name', array('@name' => $GLOBALS['language_interface']->method_id)));
27
  }
28 29 30 31 32 33 34 35 36 37 38 39 40
}

/**
 * Implements hook_language_types_info().
 */
function locale_test_language_types_info() {
  if (variable_get('locale_test_language_types', FALSE)) {
    return array(
      'test_language_type' => array(
        'name' => t('Test'),
        'description' => t('A test language type.'),
      ),
      'fixed_test_language_type' => array(
41
        'fixed' => array('test_language_negotiation_method'),
42 43 44 45 46
      ),
    );
  }
}

47 48 49 50 51
/**
 * Implements hook_language_types_info_alter().
 */
function locale_test_language_types_info_alter(array &$language_types) {
  if (variable_get('locale_test_content_language_type', FALSE)) {
52 53 54 55 56 57 58 59 60 61 62
    unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']);
  }
}

/**
 * Implements hook_language_negotiation_info().
 */
function locale_test_language_negotiation_info() {
  if (variable_get('locale_test_language_negotiation_info', FALSE)) {
    $info = array(
      'callbacks' => array(
63
        'negotiation' => 'locale_test_language_negotiation_method',
64 65 66
      ),
      'file' => drupal_get_path('module', 'locale_test') .'/locale_test.module',
      'weight' => -10,
67
      'description' => t('This is a test language negotiation method.'),
68
    );
69 70

    return array(
71
      'test_language_negotiation_method' => array(
72 73 74
        'name' => t('Test'),
        'types' => array(LANGUAGE_TYPE_CONTENT, 'test_language_type', 'fixed_test_language_type'),
      ) + $info,
75
      'test_language_negotiation_method_ts' => array(
76 77 78 79 80 81 82 83 84 85
        'name' => t('Type-specific test'),
        'types' => array('test_language_type'),
      ) + $info,
    );
  }
}

/**
 * Implements hook_language_negotiation_info_alter().
 */
86
function locale_test_language_negotiation_info_alter(array &$negotiation_info) {
87
  if (variable_get('locale_test_language_negotiation_info_alter', FALSE)) {
88
    unset($negotiation_info[LANGUAGE_NEGOTIATION_INTERFACE]);
89 90
  }
}
91 92 93 94 95 96

/**
 * Store the last negotiated languages.
 */
function locale_test_store_language_negotiation() {
  $last = array();
97
  foreach (language_types_get_all() as $type) {
98
    $last[$type] = $GLOBALS[$type]->langcode;
99 100 101 102 103
  }
  variable_set('locale_test_language_negotiation_last', $last);
}

/**
104
 * Provides a test language negotiation method.
105
 */
106
function locale_test_language_negotiation_method($languages) {
107 108
  return 'it';
}