Projet

Général

Profil

Paste
Télécharger (4,17 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / tests / theme_test.module @ db2d93dd

1
<?php
2

    
3
/**
4
 * Implements hook_theme().
5
 */
6
function theme_test_theme($existing, $type, $theme, $path) {
7
  $items['theme_test'] = array(
8
    'file' => 'theme_test.inc',
9
    'variables' => array('foo' => ''),
10
  );
11
  $items['theme_test_template_test'] = array(
12
    'template' => 'theme_test.template_test',
13
  );
14
  $items['theme_test_template_test_2'] = array(
15
    'template' => 'theme_test.template_test',
16
  );
17
  $items['theme_test_foo'] = array(
18
    'variables' => array('foo' => NULL),
19
  );
20
  return $items;
21
}
22

    
23
/**
24
 * Implements hook_system_theme_info().
25
 */
26
function theme_test_system_theme_info() {
27
  $themes['test_theme'] = drupal_get_path('module', 'theme_test') . '/themes/test_theme/test_theme.info';
28
  $themes['test_basetheme'] = drupal_get_path('module', 'theme_test') . '/themes/test_basetheme/test_basetheme.info';
29
  $themes['test_subtheme'] = drupal_get_path('module', 'theme_test') . '/themes/test_subtheme/test_subtheme.info';
30
  return $themes;
31
}
32

    
33
/**
34
 * Implements hook_menu().
35
 */
36
function theme_test_menu() {
37
  $items['theme-test/suggestion'] = array(
38
    'title' => 'Suggestion',
39
    'page callback' => '_theme_test_suggestion',
40
    'access arguments' => array('access content'),
41
    'theme callback' => '_theme_custom_theme',
42
    'type' => MENU_CALLBACK,
43
  );
44
  $items['theme-test/alter'] = array(
45
    'title' => 'Suggestion',
46
    'page callback' => '_theme_test_alter',
47
    'access arguments' => array('access content'),
48
    'theme callback' => '_theme_custom_theme',
49
    'type' => MENU_CALLBACK,
50
  );
51
  $items['theme-test/hook-init'] = array(
52
    'page callback' => 'theme_test_hook_init_page_callback',
53
    'access callback' => TRUE,
54
    'type' => MENU_CALLBACK,
55
  );
56
  $items['theme-test/drupal-add-region-content'] = array(
57
    'page callback' => '_theme_test_drupal_add_region_content',
58
    'access callback' => TRUE,
59
    'type' => MENU_CALLBACK,
60
  );
61
  return $items;
62
}
63

    
64
/**
65
 * Implements hook_init().
66
 */
67
function theme_test_init() {
68
  if (arg(0) == 'theme-test' && arg(1) == 'hook-init') {
69
    // First, force the theme registry to be rebuilt on this page request. This
70
    // allows us to test a full initialization of the theme system in the code
71
    // below.
72
    drupal_theme_rebuild();
73
    // Next, initialize the theme system by storing themed text in a global
74
    // variable. We will use this later in theme_test_hook_init_page_callback()
75
    // to test that even when the theme system is initialized this early, it is
76
    // still capable of returning output and theming the page as a whole.
77
    $GLOBALS['theme_test_output'] = theme('more_link', array('url' => 'user', 'title' => 'Themed output generated in hook_init()'));
78
  }
79
}
80

    
81
/**
82
 * Implements hook_exit().
83
 */
84
function theme_test_exit() {
85
  if (arg(0) == 'user') {
86
    // Register a fake registry loading callback. If it gets called by
87
    // theme_get_registry(), the registry has not been initialized yet.
88
    _theme_registry_callback('_theme_test_load_registry', array());
89
    print theme_get_registry() ? 'registry initialized' : 'registry not initialized';
90
  }
91
}
92

    
93
/**
94
 * Fake registry loading callback.
95
 */
96
function _theme_test_load_registry() {
97
  return array();
98
}
99

    
100
/**
101
 * Menu callback for testing themed output generated in hook_init().
102
 */
103
function theme_test_hook_init_page_callback() {
104
  return $GLOBALS['theme_test_output'];
105
}
106

    
107
/**
108
 * Custom theme callback.
109
 */
110
function _theme_custom_theme() {
111
  return 'test_theme';
112
}
113

    
114
/**
115
 * Page callback, calls drupal_alter().
116
 *
117
 * This is for testing that the theme can have hook_*_alter() implementations
118
 * that run during page callback execution, even before theme() is called for
119
 * the first time.
120
 */
121
function _theme_test_alter() {
122
  $data = 'foo';
123
  drupal_alter('theme_test_alter', $data);
124
  return "The altered data is $data.";
125
}
126

    
127
/**
128
 * Page callback, calls a theme hook suggestion.
129
 */
130
function _theme_test_suggestion() {
131
  return theme(array('theme_test__suggestion', 'theme_test'), array());
132
}
133

    
134
/**
135
 * Page callback, calls drupal_add_region_content.
136
 */
137
function _theme_test_drupal_add_region_content() {
138
  drupal_add_region_content('content', 'World');
139
  return 'Hello';
140
}
141

    
142
/**
143
 * Theme function for testing theme('theme_test_foo').
144
 */
145
function theme_theme_test_foo($variables) {
146
  return $variables['foo'];
147
}