Projet

Général

Profil

Paste
Télécharger (3,81 ko) Statistiques
| Branche: | Révision:

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

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
  return $items;
57
}
58

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

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

    
88
/**
89
 * Fake registry loading callback.
90
 */
91
function _theme_test_load_registry() {
92
  return array();
93
}
94

    
95
/**
96
 * Menu callback for testing themed output generated in hook_init().
97
 */
98
function theme_test_hook_init_page_callback() {
99
  return $GLOBALS['theme_test_output'];
100
}
101

    
102
/**
103
 * Custom theme callback.
104
 */
105
function _theme_custom_theme() {
106
  return 'test_theme';
107
}
108

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

    
122
/**
123
 * Page callback, calls a theme hook suggestion.
124
 */
125
function _theme_test_suggestion() {
126
  return theme(array('theme_test__suggestion', 'theme_test'), array());
127
}
128

    
129
/**
130
 * Theme function for testing theme('theme_test_foo').
131
 */
132
function theme_theme_test_foo($variables) {
133
  return $variables['foo'];
134
}