-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtemplate.php
More file actions
505 lines (435 loc) · 17.3 KB
/
template.php
File metadata and controls
505 lines (435 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<?php
/**
* Preprocess and Process Functions SEE: http://drupal.org/node/254940#variables-processor
* 1. Rename each function and instance of "adaptivetheme_subtheme" to match
* your subthemes name, e.g. if your theme name is "footheme" then the function
* name will be "footheme_preprocess_hook". Tip - you can search/replace
* on "adaptivetheme_subtheme".
* 2. Uncomment the required function to use.
* 3. Read carefully, especially within adaptivetheme_subtheme_preprocess_html(), there
* are extra goodies you might want to leverage such as a very simple way of adding
* stylesheets for Internet Explorer and a browser detection script to add body classes.
*/
global $theme_key, $path_to_ddbasic_core;
$theme_key = $GLOBALS['theme_key'];
$path_to_ddbasic_core = drupal_get_path('theme', 'ddbasic');
/**
* Preprocess variables for html.tpl.php
*/
function ddbasic_preprocess_html(&$vars) {
global $theme_key, $language;
$theme_name = $theme_key;
// Set variable for the base path
$vars['base_path'] = base_path();
// Clean up the lang attributes.
$vars['html_attributes'] = 'lang="' . $language->language . '" dir="' . $language->dir . '"';
}
/**
* Implements hook_preprocess_panels_pane().
*
*/
function ddbasic_preprocess_panels_pane(&$vars) {
// Suggestions base on sub-type.
$vars['theme_hook_suggestions'][] = 'panels_pane__' . str_replace('-', '__', $vars['pane']->subtype);
// Suggestions on panel pane
$vars['theme_hook_suggestions'][] = 'panels_pane__' . $vars['pane']->panel;
}
/**
* Implements hook_preprocess_views_view_unformatted().
*
* Overwrite views row classes
*/
function ddbasic_preprocess_views_view_unformatted(&$vars) {
// Class names for overwriting
$row_first = "first";
$row_last = "last";
$view = $vars['view'];
$rows = $vars['rows'];
// Set arrays
$vars['classes_array'] = array();
$vars['classes'] = array();
// Variables
$count = 0;
$max = count($rows);
// Loop through the rows and overwrite the classes, its importent that the
// $row variable is here, as it's the $id that we need.
foreach ($rows as $id => $row) {
$count++;
$vars['classes'][$id][] = $count % 2 ? 'odd' : 'even';
if ($count == 1) {
$vars['classes'][$id][] = $row_first;
}
if ($count == $max) {
$vars['classes'][$id][] = $row_last;
}
if ($row_class = $view->style_plugin->get_row_class($id)) {
$vars['classes'][$id][] = $row_class;
}
if ( $vars['classes'] && $vars['classes'][$id] ){
$vars['classes_array'][$id] = implode(' ', $vars['classes'][$id]);
} else {
$vars['classes_array'][$id] = '';
}
}
}
/**
* Implements hook_preprocess_user_picture().
*
* Override or insert variables into template user_picture.tpl.php
*
* @TODO: Is there an render array for this, str replacement is not cheap.
* @TODO: Why do we replace and insert span2 thumbnail classes? Aren't they
* bootstrap specific?
*
* @param $variables
* An array of variables to pass to the theme template.
*/
function ddbasic_preprocess_user_picture(&$variables) {
// inject the class we need into the A tag of user_picture
$variables['user_picture'] = str_replace('<a ', '<a class="span2 thumbnail" ', $variables['user_picture']);
// inject the class we need into the IMG tag of user_picture
$variables['user_picture'] = str_replace('<img ', '<img class="pull-left" ', $variables['user_picture']);
}
/**
* Implements hook_preprocess_node().
*
* Override or insert variables into the node templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("node" in this case.)
*/
function ddbasic_preprocess_node(&$variables, $hook) {
//added open graph meta tags for facebook.
$site_name = variable_get('site_name');
$og_title = $variables['node']->title . ($site_name ? ' | ' . $site_name : '');
if ($variables['type'] == 'ding_page') {
$og_description = isset($variables['node']->field_ding_page_lead[LANGUAGE_NONE][0]) ? drupal_substr(check_plain(strip_tags($variables['node']->field_ding_page_lead[LANGUAGE_NONE][0]['safe_value'])), 0, 100) . '..' : '';
$og_image = isset($variables['node']->field_ding_page_title_image[LANGUAGE_NONE][0]) ? file_create_url($variables['node']->field_ding_page_title_image[LANGUAGE_NONE][0]['uri'], array('absolute' => TRUE)) : '';
}
elseif ($variables['type'] == 'ding_news') {
$og_description = isset($variables['node']->field_ding_news_lead[LANGUAGE_NONE][0]) ? drupal_substr(check_plain(strip_tags($variables['node']->field_ding_news_lead[LANGUAGE_NONE][0]['safe_value'])), 0, 100) . '..' : '';
$og_image = isset($variables['node']->field_ding_news_title_image[LANGUAGE_NONE][0]) ? file_create_url($variables['node']->field_ding_news_title_image[LANGUAGE_NONE][0]['uri'], array('absolute' => TRUE)) : '';
}
drupal_add_html_head(array(
'#tag' => 'meta',
'#attributes' => array(
'property' => 'og:title',
'content' => $og_title,
),
), 'node_' . $variables['node']->nid . '_og_title');
drupal_add_html_head(array(
'#tag' => 'meta',
'#attributes' => array(
'property' => 'og:description',
'content' => $og_description,
),
), 'node_' . $variables['node']->nid . '_og_description');
drupal_add_html_head(array(
'#tag' => 'meta',
'#attributes' => array(
'property' => 'og:image',
'content' => $og_image,
),
), 'node_' . $variables['node']->nid . '_og_image');
// Opening hours on library list.
$hooks = theme_get_registry(FALSE);
if (isset($hooks['opening_hours_week']) && $variables['type'] == 'ding_library') {
$variables['opening_hours'] = theme('opening_hours_week', array('node' => $variables['node']));
}
// Add ddbasic_byline to variables
$variables['ddbasic_byline'] = t('By: ');
// Add ddbasic_event_location and ddbasic_place2book_tickets to variables (only for ding_event node template)
if (isset($variables['content']['#bundle']) && $variables['content']['#bundle'] == 'ding_event') {
$event_location = 'location';
if (!empty($variables['content']['field_ding_event_location'][0]['#address']['name_line'])) {
$event_location = $variables['content']['field_ding_event_location'][0]['#address']['name_line'] . '<br/>' . $variables['content']['field_ding_event_location'][0]['#address']['thoroughfare'] . ', ' . $variables['content']['field_ding_event_location'][0]['#address']['locality'];
}
else {
/**
* @TODO: the full address wil have to be retrieved from the database
*/
$event_location = render($variables['content']['field_ding_event_library'][0]);
}
$variables['ddbasic_event_location'] = $event_location;
// Set a flag for existence of field_place2book_tickets
$variables['ddbasic_place2book_tickets'] = (isset($variables['content']['field_place2book_tickets'])) ? 1: 0;
}
/**
* @TODO Use date-formats defined in the backend, do not hardcode formats...
* ever
*/
// Add updated to variables.
$variables['ddbasic_updated'] = t('Updated: !datetime', array('!datetime' => format_date($variables['node']->changed, 'custom', 'l j. F Y')));
// Modified submitted variable
if ($variables['display_submitted']) {
$variables['submitted'] = t('Submitted: !datetime', array('!datetime' => format_date($variables['created'], 'custom', 'l j. F Y')));
}
}
/**
* Implementing the ticketsinfo theme function (support for ding_place2book module)
*
* @TODO: Markup should not be hardcode into theme function as it makes it very
* hard to override.
*
*/
function ddbasic_place2book_ticketsinfo($variables) {
$output = '';
$place2book_id = $variables['place2book_id'];
$url = $variables['url'];
$type = $variables['type'];
switch ($type) {
case 'event-over':
$output = '<div class="btn-warning btn-large">' . t('The event has already taken place') . '</div>';
break;
case 'closed-admission':
$output = '<div class="btn-warning btn-large">' . t('The event is closed for admission') . '</div>';
break;
case 'sale-not-started':
$output = '<div class="btn-warning btn-large">' . t('Ticket sale has not yet started for this event') . '</div>';
break;
case 'sale-not-started':
$output = '<div class="btn-warning btn-large">' . t('Ticket sale has not yet started for this event') . '</div>';
break;
case 'no-tickets-left':
$output = '<div class="btn-warning btn-large">' . t('Sold out') . '</div>';
break;
case 'order-link':
$output = l(t('Book a ticket'), $url, array('attributes' => array('class' => array('btn', 'btn-primary', 'btn-large') , 'target' => '_blank')));
break;
default:
$output = '';
break;
}
return $output;
}
/**
* Implements template_preprocess_field().
*/
function ddbasic_preprocess_field(&$vars, $hook) {
// Get current view mode (teaser)
$view_mode = $vars['element']['#view_mode'];
$field_name = $vars['element']['#field_name'];
// Add suggestion for ddbasic specific field.
$vars['theme_hook_suggestions'][] = 'field__' . 'ddbasic';
// Add suggestion for ddbasic field with specific name.
$vars['theme_hook_suggestions'][] = 'field__' . 'ddbasic_' . $field_name;
// Add suggestion for ddbasic field in specific view mode.
$vars['theme_hook_suggestions'][] = 'field__' . 'ddbasic_' . $view_mode;
// Clean up fields in search result view mode aka. search result page.
if ($view_mode == 'search_result') {
// Add suggestion that only hits the search result page.
$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . $view_mode;
switch ($vars['element']['#field_name']) {
case 'ting_author':
case 'ting_abstract':
case 'ting_subjects':
$vars['classes_array'] = array('content');
break;
case 'ting_title':
$vars['classes_array'] = array('heading');
break;
}
}
// Make suggestion for the availability on the search result page.
if ($vars['element']['#field_type'] == 'ting_collection_types' &&
$vars['element']['#formatter'] == 'ding_availability_types') {
$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . 'search_result';
// Add class to availability list.
}
}
/**
* Implements ding_footer_preprocess().
*
* Find the right grid classes to add to the different footer columns.
*/
function ddbasic_preprocess_ding_footer_blocks(&$vars) {
$number_of_blocks = count($vars['blocks']);
switch ($number_of_blocks) {
case 1:
$classes = array('grid-full');
break;
case 2:
$classes = array(
'grid-8-left',
'grid-8-right'
);
break;
case 3:
$classes = array(
'grid-4-left',
'grid-8-center',
'grid-4-right'
);
break;
case 4:
$classes = array(
'grid-4-left',
'grid-4-center-left',
'grid-4-center-right',
'grid-4-right'
);
break;
default:
$classes = array('grid-full');
break;
}
$vars['grid_classes'] = $classes;
}
/**
* OLD FUNCTION FROM LATTO MOVED HERE
*
* * Implements theme_form_alter().
*
* Adds two bootstrap classes to the default Drupal search form submit button.
* Adds the default-value to the search field.
*
* @param type $vars
*
function latto_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == "search_block_form") {
$form['search_block_form']['#attributes']['title'] = t('Søg efter materialer fra biblioteket..');
// Add a specify class to the search form to tell JavaScript this should
// have the example functionallyty functionality.
$form['search_block_form']['#attributes']['class'][] = 'has-example';
$form['actions']['submit']['#attributes']['class'][] = 'btn';
$form['actions']['submit']['#attributes']['class'][] = 'btn-large';
$form['actions']['submit']['#attributes']['class'][] = 'btn-info';
}
}
* /**
* Implement theme_breadcrumb().
*
* Implemented for the purpose of changing >> to > in the default breadcrumb.
*
function latto_breadcrumb ($variables) {
$breadcrumb = $variables['breadcrumb'];
if(!empty($breadcrumb)) {
return '<div class="breadcrumb">' . implode(' > ', $breadcrumb) . '</div>';
}
}
* /**
* Implements hook_preprocess_user_picture().
*
* Override or insert variables into template user_picture.tpl.php
*
* @TODO: Is there an render array for this, str replacement is not cheap.
*
* @param $variables
* An array of variables to pass to the theme template.
*
function latto_preprocess_user_picture(&$variables) {
// inject the class we need into the A tag of user_picture
$variables['user_picture'] = str_replace('<a ', '<a class="span2 thumbnail" ', $variables['user_picture']);
// inject the class we need into the IMG tag of user_picture
$variables['user_picture'] = str_replace('<img ', '<img class="pull-left" ', $variables['user_picture']);
}
*
* /**
* Implements hook_preprocess_node().
*
* Override or insert variables into the node templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("node" in this case.)
*
function latto_preprocess_node(&$variables, $hook) {
// Add latto_byline to variables
$variables['latto_byline'] = t('By: ');
// Add latto_event_location and latto_place2book_tickets to variables (only for ding_event node template)
if (isset($variables['content']['#bundle']) && $variables['content']['#bundle'] == 'ding_event') {
$event_location = 'location';
if (!empty($variables['content']['field_address'][0]['#address']['name_line'])) {
$event_location = $variables['content']['field_address'][0]['#address']['name_line'] . '<br/>' . $variables['content']['field_address'][0]['#address']['thoroughfare'] . ', ' . $variables['content']['field_address'][0]['#address']['locality'];
}
else {
// @TODO: the full address wil have to be retrieved from the database
$event_location = render($variables['content']['group_audience'][0]);
}
$variables['latto_event_location'] = $event_location;
// Set a flag for existence of field_place2book_tickets
$variables['latto_place2book_tickets'] = (isset($variables['content']['field_place2book_tickets'])) ? 1: 0;
}
// Add latto_ding_content_tags to variables.
$variables['latto_ding_content_tags'] = '';
if (isset($variables['content']['ding_content_tags'])) {
$latto_ding_content_tags = '';
$items = $variables['content']['ding_content_tags']['#items'];
if (count($items) > 0) {
foreach ($items as $delta => $item) {
$latto_ding_content_tags .= render($variables['content']['ding_content_tags'][$delta]);
if ($delta != count($items)-1) {
$latto_ding_content_tags .= ', ';
}
}
$variables['latto_ding_content_tags'] = t('Tags: ') . $latto_ding_content_tags;
}
}
/**
* @TODO Use date-formats defined in the backend, do not hardcode formats...
* ever
*
// Add updated to variables.
$variables['latto_updated'] = t('Updated: !datetime', array('!datetime' => format_date($variables['node']->changed, 'custom', 'l j. F Y')));
// Modified submitted variable
if ($variables['display_submitted']) {
$variables['submitted'] = t('Submitted: !datetime', array('!datetime' => format_date($variables['created'], 'custom', 'l j. F Y')));
}
}
*
/**
* Implementing the ticketsinfo theme function (support for ding_place2book module)
*
* @TODO: Markup should not be hardcode into theme function as it makes it very
* hard to override.
*
function latto_place2book_ticketsinfo($variables) {
$output = '';
$url = $variables['url'];
$type = $variables['type'];
switch ($type) {
case 'event-over':
$output = '<button class="btn btn-warning btn-large">' . t('The event has already taken place') . '</button>';
break;
case 'closed-admission':
$output = '<button class="btn btn-warning btn-large">' . t('Not open for ticket sale') . '</button>';
break;
case 'no-tickets-left':
$output = '<button class="btn btn-warning btn-large">' . t('Sold out') . '</button>';
break;
case 'order-link':
$output = l(t('Book a ticket'), $url, array('attributes' => array('class' => array('btn', 'btn-primary', 'btn-large'))));
break;
default:
$output = '';
break;
}
return $output;
}
function hook_preprocess_field($vars){
// Clean up fields in search result view mode aka. search result page.
if ($view_mode == 'search_result') {
// Add suggestion that only hits the search result page.
$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . $view_mode;
switch ($vars['element']['#field_name']) {
case 'ting_author':
case 'ting_abstract':
case 'ting_subjects':
$vars['classes_array'] = array('content');
break;
case 'ting_title':
$vars['classes_array'] = array('heading');
break;
}
}
// Make suggestion for the availability on the search result page.
if ($vars['element']['#field_type'] == 'ting_collection_types' &&
$vars['element']['#formatter'] == 'ding_availability_types') {
$vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . 'search_result';
// Add class to availability list.
}
}
*/