Projet

Général

Profil

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

root / drupal7 / sites / all / themes / bootstrap / templates / system / link.vars.php @ 7547bb19

1
<?php
2

    
3
/**
4
 * @file
5
 * Stub file for "link" theme hook [pre]process functions.
6
 */
7

    
8
/**
9
 * Pre-processes variables for the "link" theme hook.
10
 *
11
 * See theme function for list of available variables.
12
 *
13
 * @see bootstrap_process_link()
14
 * @see theme_link()
15
 *
16
 * @ingroup theme_preprocess
17
 */
18
function bootstrap_preprocess_link(&$variables) {
19
  // Fill in missing defaults not provided by drupal_common_theme().
20
  $variables['options'] += array(
21
    'attributes' => array(),
22
    'html' => FALSE,
23
  );
24
  
25
  // Core is so backwards on this theme hook. It does not provide a proper
26
  // preprocess function or attributes array. Merge any passed attributes
27
  // (which take precedence over passed option attributes) into the options
28
  // attributes array.
29
  if (!empty($variables['attributes'])) {
30
    $variables['options']['attributes'] = drupal_array_merge_deep($variables['options']['attributes'], $variables['attributes']);
31
  }
32

    
33
  // Standardize "attributes" by referencing the attributes in options.
34
  $variables['attributes'] = &$variables['options']['attributes'];
35

    
36
  // Add the icon position class.
37
  if (!empty($variables['icon'])) {
38
    _bootstrap_add_class('icon-' . drupal_html_class($variables['icon_position'] === 'icon_only' ? 'only' : $variables['icon_position']), $variables);
39
  }
40

    
41
  // Remove any "href" attribute since it's manually added in theme_link().
42
  unset($variables['attributes']['href']);
43
}
44

    
45
/**
46
 * Processes variables for the "link" theme hook.
47
 *
48
 * See theme function for list of available variables.
49
 *
50
 * @see bootstrap_preprocess_link()
51
 * @see theme_link()
52
 *
53
 * @ingroup theme_process
54
 */
55
function bootstrap_process_link(&$variables) {
56
  // Render #icon and trim it (so it doesn't add underlines in whitespace).
57
  if (!empty($variables['icon']) && ($icon = trim(render($variables['icon'])))) {
58
    // Sanitize text, if necessary.
59
    $variables['text'] = !empty($variables['options']['html']) ? $variables['text'] : check_plain($variables['text']);
60

    
61
    // Override the HTML option so icon is printed.
62
    $variables['options']['html'] = TRUE;
63

    
64
    // Hide the link text, if necessary.
65
    if ($variables['icon_position'] === 'icon_only') {
66
      $variables['text'] = '<span class="sr-only">' . $variables['text'] . '</span>';
67
    }
68
    if ($variables['icon_position'] === 'after') {
69
      $variables['text'] .= $icon;
70
    }
71
    else {
72
      $variables['text'] = $icon . $variables['text'];
73
    }
74
  }
75
}