Projet

Général

Profil

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

root / drupal7 / sites / all / themes / bootstrap / templates / date / date-views-pager.vars.php @ 7547bb19

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

    
7
/**
8
 * Pre-processes variables for the "date_views_pager" theme hook.
9
 *
10
 * See template for list of available variables.
11
 *
12
 * @see date-views-pager.tpl.php
13
 *
14
 * @ingroup theme_preprocess
15
 */
16
function bootstrap_preprocess_date_views_pager(&$variables) {
17
  $mini = !empty($variables['mini']);
18

    
19
  // Link types.
20
  $types = array(
21
    // Because this is using the "date_nav" context, this must use "Prev"
22
    // instead of the full English word "Previous".
23
    // @todo Should this be fixed upstream in the date/date_views module?
24
    'prev' => t('Prev', array(), array('context' => 'date_nav')),
25
    'next' => t('Next', array(), array('context' => 'date_nav')),
26
  );
27

    
28
  // Icon map.
29
  $icons = array(
30
    'prev' => array(
31
      'name' => 'menu-left',
32
      'default' => '&laquo;&nbsp;',
33
      'position' => 'before',
34
    ),
35
    'next' => array(
36
      'name' => 'menu-right',
37
      'default' => '&nbsp;&raquo;',
38
      'position' => 'after',
39
    ),
40
  );
41

    
42
  // Create necessary links.
43
  $items = [];
44
  foreach ($types as $type => $text) {
45
    $item_classes = array($type);
46

    
47
    $options = isset($variables[$type . '_options']) ? $variables[$type . '_options']: array();
48
    $options += array('attributes' => array());
49

    
50
    $url = $variables[$type . '_url'];
51
    // Make the item disabled if there is no URL.
52
    if (!$url) {
53
      $url = '#';
54
      $item_classes[] = 'disabled';
55
      $options['absolute'] = TRUE;
56
      $options['external'] = TRUE;
57
    }
58
    // Convert titles into tooltips, if enabled.
59
    elseif (!empty($options['attributes']['title']) && bootstrap_setting('tooltip_enabled')) {
60
      $options['attributes']['data-toggle'] = 'tooltip';
61
      $options['attributes']['data-placement'] = 'bottom';
62
    }
63

    
64
    // Create a link.
65
    $link = array(
66
      '#theme' => 'link__date_views__pager__' . $type,
67
      '#text' => $text,
68
      '#path' => $url,
69
      '#options' => $options,
70
    );
71

    
72
    // Add relevant icon.
73
    if (isset($icons[$type])) {
74
      $icon = $icons[$type];
75
      $link['#icon'] = _bootstrap_icon($icon['name'], $icon['default']);
76
      $link['#icon_position'] = $mini ? 'icon_only' : $icon['position'];
77
    }
78

    
79
    $items[$type] = array(
80
      'class' => $item_classes,
81
      'data' => $link,
82
    );
83
  }
84

    
85
  // Add items render array.
86
  $variables['items'] = array(
87
    '#theme' => 'item_list__date_views__pager',
88
    '#attributes' => array('class' => array('pagination', 'pull-right')),
89
    '#items' => $items,
90
  );
91

    
92
  // Add default classes for the <nav> wrapper.
93
  $variables['attributes_array']['class'][] = 'clearfix';
94
  $variables['attributes_array']['class'][] = 'date-nav-wrapper';
95

    
96
  // This is not mentioned anywhere other than in the original module's
97
  // template file. However, to keep BC, these need to be merged just in case.
98
  if (!empty($variables['extra_classes'])) {
99
    if (is_string($variables['extra_classes'])) {
100
      $variables['extra_classes'] = explode(' ', $variables['extra_classes']);
101
    }
102
    $variables['attributes_array']['class'] = array_merge(isset($variables['attributes']['class']) ? $variables['attributes']['class'] : array(), $variables['extra_classes']);
103
  }
104
}