Projet

Général

Profil

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

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

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

    
7
/**
8
 * Pre-processes variables for the "bootstrap_dropdown" theme hook.
9
 *
10
 * See theme function for list of available variables.
11
 *
12
 * @see bootstrap_bootstrap_dropdown()
13
 *
14
 * @ingroup theme_preprocess
15
 */
16
function bootstrap_preprocess_bootstrap_dropdown(&$variables) {
17
  $element = &$variables['element'];
18

    
19
  // Provide defaults.
20
  $element += array(
21
    '#wrapper_attributes' => NULL,
22
    '#attributes' => NULL,
23
    '#alignment' => NULL,
24
    '#toggle' => NULL,
25
    '#items' => NULL,
26
  );
27

    
28
  // Dropdown vertical alignment.
29
  $element['#wrapper_attributes']['class'][] = 'dropdown';
30
  if ($element['#alignment'] === 'up' || (is_array($element['#alignment']) && in_array('up', $element['#alignment']))) {
31
    $element['#wrapper_attributes']['class'][] = 'dropup';
32
  }
33

    
34
  if (isset($element['#toggle'])) {
35
    if (is_string($element['#toggle'])) {
36
      $element['#toggle'] = array(
37
        '#theme' => 'link__bootstrap_dropdown__toggle',
38
        '#text' => filter_xss_admin($element['#toggle']),
39
        '#path' => '#',
40
        '#options' => array(
41
          'attributes' => array(),
42
          'html' => TRUE,
43
          'external' => TRUE,
44
        ),
45
      );
46
    }
47
    if (isset($element['#toggle']['#options']['attributes'])) {
48
      $element['#toggle']['#options']['attributes']['class'][] = 'dropdown-toggle';
49
      $element['#toggle']['#options']['attributes']['data-toggle'] = 'dropdown';
50
    }
51
    else {
52
      $element['#toggle']['#attributes']['class'][] = 'dropdown-toggle';
53
      $element['#toggle']['#attributes']['data-toggle'] = 'dropdown';
54
    }
55
  }
56

    
57
  // Menu items.
58
  $element['#attributes']['role'] = 'menu';
59
  $element['#attributes']['class'][] = 'dropdown-menu';
60
  if ($element['#alignment'] === 'right' || (is_array($element['#alignment']) && in_array('right', $element['#alignment']))) {
61
    $element['#attributes']['class'][] = 'dropdown-menu-right';
62
  }
63
}
64

    
65
/**
66
 * Processes variables for the "bootstrap_dropdown" theme hook.
67
 *
68
 * See theme function for list of available variables.
69
 *
70
 * @see bootstrap_bootstrap_dropdown()
71
 *
72
 * @ingroup theme_process
73
 */
74
function bootstrap_process_bootstrap_dropdown(&$variables) {
75
  $element = &$variables['element'];
76

    
77
  $items = array();
78
  foreach ($element['#items'] as $data) {
79
    $item_classes = array();
80

    
81
    // Dividers.
82
    if (empty($data)) {
83
      $data = '';
84
      $item_classes[] = 'divider';
85
    }
86
    // Headers (must be a string).
87
    elseif (is_array($data) && (!empty($data['header']) || !empty($data['#header']))) {
88
      $item_classes[] = 'dropdown-header';
89
    }
90
    // Disabled.
91
    elseif (is_array($data) && (!empty($data['disabled']) || !empty($data['#disabled']))) {
92
      $item_classes[] = 'disabled';
93
    }
94
    // Active.
95
    elseif (is_array($data) && (!empty($data['active']) || !empty($data['#active']))) {
96
      $item_classes[] = 'active';
97
    }
98

    
99
    // Construct item_list item.
100
    $item = array(
101
      'data' => render($data),
102
      'role' => 'presentation',
103
    );
104
    if (!empty($item_classes)) {
105
      $item['class'] = $item_classes;
106
    }
107
    $items[] = $item;
108
  }
109

    
110
  // Create the dropdown.
111
  $variables['dropdown'] = array(
112
    '#theme_wrappers' => array('container'),
113
    '#attributes' => $element['#wrapper_attributes'],
114
    'toggle' => $element['#toggle'],
115
    'items' => array(
116
      '#theme' => 'item_list__bootstrap_dropdown',
117
      '#items' => $items,
118
      '#attributes' => $element['#attributes'],
119
    ),
120
  );
121
}