language_test.module 2.64 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Mock module for language layer tests.
6
7
 */

8
9
10
/**
 * Implements hook_init().
 */
11
12
function language_test_init() {
  language_test_store_language_negotiation();
13
14
  if (isset(language(LANGUAGE_TYPE_INTERFACE)->langcode) && isset(language(LANGUAGE_TYPE_INTERFACE)->method_id)) {
    drupal_set_message(t('Language negotiation method: @name', array('@name' => language(LANGUAGE_TYPE_INTERFACE)->method_id)));
15
  }
16
17
18
19
20
}

/**
 * Implements hook_language_types_info().
 */
21
function language_test_language_types_info() {
22
  if (state()->get('language_test.language_types')) {
23
24
25
26
27
28
    return array(
      'test_language_type' => array(
        'name' => t('Test'),
        'description' => t('A test language type.'),
      ),
      'fixed_test_language_type' => array(
29
        'fixed' => array('test_language_negotiation_method'),
30
31
32
33
34
      ),
    );
  }
}

35
36
37
/**
 * Implements hook_language_types_info_alter().
 */
38
function language_test_language_types_info_alter(array &$language_types) {
39
  if (state()->get('language_test.content_language_type')) {
40
41
42
43
44
45
46
    unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']);
  }
}

/**
 * Implements hook_language_negotiation_info().
 */
47
function language_test_language_negotiation_info() {
48
  if (state()->get('language_test.language_negotiation_info')) {
49
50
    $info = array(
      'callbacks' => array(
51
        'negotiation' => 'language_test_language_negotiation_method',
52
      ),
53
      'file' => drupal_get_path('module', 'language_test') .'/language_test.module',
54
      'weight' => -10,
55
      'description' => t('This is a test language negotiation method.'),
56
    );
57
58

    return array(
59
      'test_language_negotiation_method' => array(
60
61
62
        'name' => t('Test'),
        'types' => array(LANGUAGE_TYPE_CONTENT, 'test_language_type', 'fixed_test_language_type'),
      ) + $info,
63
      'test_language_negotiation_method_ts' => array(
64
65
66
67
68
69
70
71
72
73
        'name' => t('Type-specific test'),
        'types' => array('test_language_type'),
      ) + $info,
    );
  }
}

/**
 * Implements hook_language_negotiation_info_alter().
 */
74
function language_test_language_negotiation_info_alter(array &$negotiation_info) {
75
  if (state()->get('language_test.language_negotiation_info_alter')) {
76
    unset($negotiation_info[LANGUAGE_NEGOTIATION_INTERFACE]);
77
78
  }
}
79
80
81
82

/**
 * Store the last negotiated languages.
 */
83
function language_test_store_language_negotiation() {
84
  $last = array();
85
  foreach (language_types_get_all() as $type) {
86
    $last[$type] = language($type)->langcode;
87
  }
88
  state()->set('language_test.language_negotiation_last', $last);
89
90
91
}

/**
92
 * Provides a test language negotiation method.
93
 */
94
function language_test_language_negotiation_method($languages) {
95
96
  return 'it';
}