Projet

Général

Profil

Paste
Télécharger (2,38 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / templates / bootstrap / bootstrap-carousel.vars.php @ 7547bb19

1
<?php
2
/**
3
 * @file
4
 * Stub file for "bootstrap_carousel" theme hook [pre]process functions.
5
 */
6

    
7
/**
8
 * Pre-processes variables for the "bootstrap_carousel" theme hook.
9
 *
10
 * See template for list of available variables.
11
 *
12
 * @see bootstrap-carousel.tpl.php
13
 *
14
 * @ingroup theme_preprocess
15
 */
16
function bootstrap_preprocess_bootstrap_carousel(&$variables) {
17
  $variables['attributes']['class'][] = 'carousel';
18
  $variables['attributes']['class'][] = 'slide';
19
  $variables['attributes']['data-ride'] = 'carousel';
20
  if (empty($variables['attributes']['id'])) {
21
    $variables['attributes']['id'] = drupal_html_id('carousel');
22
  }
23
  $default_data_attributes = array(
24
    'interval' => 5000,
25
    'pause' => TRUE,
26
    'wrap' => TRUE,
27
  );
28
  foreach ($default_data_attributes as $name => $value) {
29
    if ($variables[$name] !== $value) {
30
      // Convert PHP booleans to the JSON equivalent, otherwise they'll be
31
      // interpreted as integers when they're parsed.
32
      if (is_bool($variables[$name])) {
33
        $variables[$name] = $variables[$name] ? 'true' : 'false';
34
      }
35
      $variables['attributes']['data-' . $name] = $variables[$name];
36
    }
37
  }
38
}
39

    
40
/**
41
 * Processes variables for the "bootstrap_carousel" theme hook.
42
 *
43
 * See template for list of available variables.
44
 *
45
 * @see bootstrap-carousel.tpl.php
46
 *
47
 * @ingroup theme_process
48
 */
49
function bootstrap_process_bootstrap_carousel(&$variables) {
50
  $variables['target'] = '#' . $variables['attributes']['id'];
51
  $variables['attributes'] = drupal_attributes($variables['attributes']);
52

    
53
  // Ensure the item arrays are constructed properly for the template.
54
  foreach ($variables['items'] as $delta => $item) {
55
    // Convert items that are string into the appropriate array structure.
56
    if (is_string($item)) {
57
      $variables['items'][$delta] = array(
58
        'image' => $item,
59
      );
60
    }
61
    // Populate defaults.
62
    $variables['items'][$delta] += array(
63
      'title' => NULL,
64
      'description' => NULL,
65
      'url' => NULL,
66
    );
67

    
68
    if (!empty($variables['items'][$delta]['title'])) {
69
      $variables['items'][$delta]['title'] = is_scalar($item['title']) ? filter_xss_admin($item['title']) : render($item['title']);
70
    }
71

    
72
    if (!empty($variables['items'][$delta]['description'])) {
73
      $variables['items'][$delta]['description'] = is_scalar($item['description']) ? filter_xss_admin($item['description']) : render($item['description']);
74
    }
75

    
76
  }
77
}