Project

General

Profile

Download (9.34 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Contains the theme's functions to manipulate Drupal's default markup.
5
 *
6
 * A QUICK OVERVIEW OF DRUPAL THEMING
7
 *
8
 *   The default HTML for all of Drupal's markup is specified by its modules.
9
 *   For example, the comment.module provides the default HTML markup and CSS
10
 *   styling that is wrapped around each comment. Fortunately, each piece of
11
 *   markup can optionally be overridden by the theme.
12
 *
13
 *   Drupal deals with each chunk of content using a "theme hook". The raw
14
 *   content is placed in PHP variables and passed through the theme hook, which
15
 *   can either be a template file (which you should already be familiary with)
16
 *   or a theme function. For example, the "comment" theme hook is implemented
17
 *   with a comment.tpl.php template file, but the "breadcrumb" theme hooks is
18
 *   implemented with a theme_breadcrumb() theme function. Regardless if the
19
 *   theme hook uses a template file or theme function, the template or function
20
 *   does the same kind of work; it takes the PHP variables passed to it and
21
 *   wraps the raw content with the desired HTML markup.
22
 *
23
 *   Most theme hooks are implemented with template files. Theme hooks that use
24
 *   theme functions do so for performance reasons - theme_field() is faster
25
 *   than a field.tpl.php - or for legacy reasons - theme_breadcrumb() has "been
26
 *   that way forever."
27
 *
28
 *   The variables used by theme functions or template files come from a handful
29
 *   of sources:
30
 *   - the contents of other theme hooks that have already been rendered into
31
 *     HTML. For example, the HTML from theme_breadcrumb() is put into the
32
 *     $breadcrumb variable of the page.tpl.php template file.
33
 *   - raw data provided directly by a module (often pulled from a database)
34
 *   - a "render element" provided directly by a module. A render element is a
35
 *     nested PHP array which contains both content and meta data with hints on
36
 *     how the content should be rendered. If a variable in a template file is a
37
 *     render element, it needs to be rendered with the render() function and
38
 *     then printed using:
39
 *       <?php print render($variable); ?>
40
 *
41
 * ABOUT THE TEMPLATE.PHP FILE
42
 *
43
 *   The template.php file is one of the most useful files when creating or
44
 *   modifying Drupal themes. With this file you can do three things:
45
 *   - Modify any theme hooks variables or add your own variables, using
46
 *     preprocess or process functions.
47
 *   - Override any theme function. That is, replace a module's default theme
48
 *     function with one you write.
49
 *   - Call hook_*_alter() functions which allow you to alter various parts of
50
 *     Drupal's internals, including the render elements in forms. The most
51
 *     useful of which include hook_form_alter(), hook_form_FORM_ID_alter(),
52
 *     and hook_page_alter(). See api.drupal.org for more information about
53
 *     _alter functions.
54
 *
55
 * OVERRIDING THEME FUNCTIONS
56
 *
57
 *   If a theme hook uses a theme function, Drupal will use the default theme
58
 *   function unless your theme overrides it. To override a theme function, you
59
 *   have to first find the theme function that generates the output. (The
60
 *   api.drupal.org website is a good place to find which file contains which
61
 *   function.) Then you can copy the original function in its entirety and
62
 *   paste it in this template.php file, changing the prefix from theme_ to
63
 *   STARTERKIT_. For example:
64
 *
65
 *     original, found in modules/field/field.module: theme_field()
66
 *     theme override, found in template.php: STARTERKIT_field()
67
 *
68
 *   where STARTERKIT is the name of your sub-theme. For example, the
69
 *   zen_classic theme would define a zen_classic_field() function.
70
 *
71
 *   Note that base themes can also override theme functions. And those
72
 *   overrides will be used by sub-themes unless the sub-theme chooses to
73
 *   override again.
74
 *
75
 *   Zen core only overrides one theme function. If you wish to override it, you
76
 *   should first look at how Zen core implements this function:
77
 *     theme_breadcrumbs()      in zen/template.php
78
 *
79
 *   For more information, please visit the Theme Developer's Guide on
80
 *   Drupal.org: http://drupal.org/node/173880
81
 *
82
 * CREATE OR MODIFY VARIABLES FOR YOUR THEME
83
 *
84
 *   Each tpl.php template file has several variables which hold various pieces
85
 *   of content. You can modify those variables (or add new ones) before they
86
 *   are used in the template files by using preprocess functions.
87
 *
88
 *   This makes THEME_preprocess_HOOK() functions the most powerful functions
89
 *   available to themers.
90
 *
91
 *   It works by having one preprocess function for each template file or its
92
 *   derivatives (called theme hook suggestions). For example:
93
 *     THEME_preprocess_page    alters the variables for page.tpl.php
94
 *     THEME_preprocess_node    alters the variables for node.tpl.php or
95
 *                              for node--forum.tpl.php
96
 *     THEME_preprocess_comment alters the variables for comment.tpl.php
97
 *     THEME_preprocess_block   alters the variables for block.tpl.php
98
 *
99
 *   For more information on preprocess functions and theme hook suggestions,
100
 *   please visit the Theme Developer's Guide on Drupal.org:
101
 *   http://drupal.org/node/223440 and http://drupal.org/node/1089656
102
 */
103

    
104

    
105
/**
106
 * Override or insert variables into the maintenance page template.
107
 *
108
 * @param $variables
109
 *   An array of variables to pass to the theme template.
110
 * @param $hook
111
 *   The name of the template being rendered ("maintenance_page" in this case.)
112
 */
113
/* -- Delete this line if you want to use this function
114
function STARTERKIT_preprocess_maintenance_page(&$variables, $hook) {
115
  // When a variable is manipulated or added in preprocess_html or
116
  // preprocess_page, that same work is probably needed for the maintenance page
117
  // as well, so we can just re-use those functions to do that work here.
118
  STARTERKIT_preprocess_html($variables, $hook);
119
  STARTERKIT_preprocess_page($variables, $hook);
120
}
121
// */
122

    
123
/**
124
 * Override or insert variables into the html templates.
125
 *
126
 * @param $variables
127
 *   An array of variables to pass to the theme template.
128
 * @param $hook
129
 *   The name of the template being rendered ("html" in this case.)
130
 */
131
/* -- Delete this line if you want to use this function
132
function STARTERKIT_preprocess_html(&$variables, $hook) {
133
  $variables['sample_variable'] = t('Lorem ipsum.');
134

    
135
  // The body tag's classes are controlled by the $classes_array variable. To
136
  // remove a class from $classes_array, use array_diff().
137
  //$variables['classes_array'] = array_diff($variables['classes_array'], array('class-to-remove'));
138
}
139
// */
140

    
141
/**
142
 * Override or insert variables into the page templates.
143
 *
144
 * @param $variables
145
 *   An array of variables to pass to the theme template.
146
 * @param $hook
147
 *   The name of the template being rendered ("page" in this case.)
148
 */
149
/* -- Delete this line if you want to use this function
150
function STARTERKIT_preprocess_page(&$variables, $hook) {
151
  $variables['sample_variable'] = t('Lorem ipsum.');
152
}
153
// */
154

    
155
/**
156
 * Override or insert variables into the node templates.
157
 *
158
 * @param $variables
159
 *   An array of variables to pass to the theme template.
160
 * @param $hook
161
 *   The name of the template being rendered ("node" in this case.)
162
 */
163
/* -- Delete this line if you want to use this function
164
function STARTERKIT_preprocess_node(&$variables, $hook) {
165
  $variables['sample_variable'] = t('Lorem ipsum.');
166

    
167
  // Optionally, run node-type-specific preprocess functions, like
168
  // STARTERKIT_preprocess_node_page() or STARTERKIT_preprocess_node_story().
169
  $function = __FUNCTION__ . '_' . $variables['node']->type;
170
  if (function_exists($function)) {
171
    $function($variables, $hook);
172
  }
173
}
174
// */
175

    
176
/**
177
 * Override or insert variables into the comment templates.
178
 *
179
 * @param $variables
180
 *   An array of variables to pass to the theme template.
181
 * @param $hook
182
 *   The name of the template being rendered ("comment" in this case.)
183
 */
184
/* -- Delete this line if you want to use this function
185
function STARTERKIT_preprocess_comment(&$variables, $hook) {
186
  $variables['sample_variable'] = t('Lorem ipsum.');
187
}
188
// */
189

    
190
/**
191
 * Override or insert variables into the region templates.
192
 *
193
 * @param $variables
194
 *   An array of variables to pass to the theme template.
195
 * @param $hook
196
 *   The name of the template being rendered ("region" in this case.)
197
 */
198
/* -- Delete this line if you want to use this function
199
function STARTERKIT_preprocess_region(&$variables, $hook) {
200
  // Don't use Zen's region--sidebar.tpl.php template for sidebars.
201
  //if (strpos($variables['region'], 'sidebar_') === 0) {
202
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('region__sidebar'));
203
  //}
204
}
205
// */
206

    
207
/**
208
 * Override or insert variables into the block templates.
209
 *
210
 * @param $variables
211
 *   An array of variables to pass to the theme template.
212
 * @param $hook
213
 *   The name of the template being rendered ("block" in this case.)
214
 */
215
/* -- Delete this line if you want to use this function
216
function STARTERKIT_preprocess_block(&$variables, $hook) {
217
  // Add a count to all the blocks in the region.
218
  // $variables['classes_array'][] = 'count-' . $variables['block_id'];
219

    
220
  // By default, Zen will use the block--no-wrapper.tpl.php for the main
221
  // content. This optional bit of code undoes that:
222
  //if ($variables['block_html_id'] == 'block-system-main') {
223
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('block__no_wrapper'));
224
  //}
225
}
226
// */
(7-7/8)