Project

General

Profile

Paste
Download (3.83 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / themes / bootstrap / templates / bootstrap / bootstrap-panel.vars.php @ 01f36513

1
<?php
2

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

    
8
/**
9
 * Pre-processes variables for the "bootstrap_panel" theme hook.
10
 *
11
 * See template for list of available variables.
12
 *
13
 * @param array $variables
14
 *   An associative array of variables, passed by reference.
15
 *
16
 * @see bootstrap-panel.tpl.php
17
 *
18
 * @ingroup theme_preprocess
19
 */
20
function bootstrap_preprocess_bootstrap_panel(array &$variables) {
21
  // Temporarily provide field_group "support" until properly "fixed" upstream.
22
  // @see https://www.drupal.org/project/bootstrap/issues/2910624
23
  if (!empty($variables['element']['#group']->format_type) && $variables['element']['#group']->format_type == 'htab') {
24
    $variables['element']['#collapsed'] = FALSE;
25
  }
26

    
27
  $element = &$variables['element'];
28

    
29
  // Set the element's attributes.
30
  element_set_attributes($element, array('id'));
31

    
32
  // Retrieve the attributes for the element.
33
  $attributes = &_bootstrap_get_attributes($element);
34

    
35
  // Add panel and panel-default classes.
36
  $attributes['class'][] = 'panel';
37
  $attributes['class'][] = 'panel-default';
38

    
39
  // states.js requires form-wrapper on fieldset to work properly.
40
  $attributes['class'][] = 'form-wrapper';
41

    
42
  // Handle collapsible panels.
43
  $variables['collapsible'] = FALSE;
44
  if (isset($element['#collapsible'])) {
45
    $variables['collapsible'] = $element['#collapsible'];
46
  }
47
  $variables['collapsed'] = FALSE;
48
  if (isset($element['#collapsed'])) {
49
    $variables['collapsed'] = $element['#collapsed'];
50
    // Remove collapsed class as it should only be applied to the body.
51
    _bootstrap_remove_class('collapsed', $element);
52
  }
53

    
54
  // Generate a unique identifier for the fieldset wrapper.
55
  if (!isset($attributes['id'])) {
56
    $attributes['id'] = drupal_html_id('bootstrap-panel');
57
  }
58

    
59
  // Get body attributes.
60
  $body_attributes = &_bootstrap_get_attributes($element, 'body_attributes');
61

    
62
  _bootstrap_add_class('panel-body', $element, 'body_attributes');
63

    
64
  // Add default .panel-body class.
65
  $body_classes = array('panel-body');
66

    
67
  // Add more classes to the body if collapsible.
68
  if ($variables['collapsible']) {
69
    $body_classes[] = 'panel-collapse';
70
    $body_classes[] = 'collapse';
71
    $body_classes[] = 'fade';
72
    $body_classes[] = $variables['collapsed'] ? 'collapsed' : 'in';
73
  }
74
  _bootstrap_add_class($body_classes, $element, 'body_attributes');
75

    
76
  // Generate a unique identifier for the body.
77
  if (!isset($body_attributes['id'])) {
78
    $body_attributes['id'] = drupal_html_id($attributes['id'] . '--body');
79
  }
80

    
81
  // Set the target to the body element.
82
  $variables['target'] = '#' . $body_attributes['id'];
83

    
84
  // Build the panel content.
85
  $variables['content'] = $element['#children'];
86
  if (isset($element['#value'])) {
87
    $variables['content'] .= $element['#value'];
88
  }
89

    
90
  // Iterate over optional variables.
91
  $keys = array(
92
    'description',
93
    'prefix',
94
    'suffix',
95
    'title',
96
  );
97
  foreach ($keys as $key) {
98
    $variables[$key] = !empty($element["#$key"]) ? $element["#$key"] : FALSE;
99
  }
100

    
101
  // Add the attributes.
102
  $variables['attributes'] = $attributes;
103
  $variables['body_attributes'] = $body_attributes;
104
}
105

    
106
/**
107
 * Processes variables for the "bootstrap_panel" theme hook.
108
 *
109
 * See template for list of available variables.
110
 *
111
 * @param array $variables
112
 *   An associative array of variables, passed by reference.
113
 *
114
 * @see bootstrap-panel.tpl.php
115
 *
116
 * @ingroup theme_process
117
 */
118
function bootstrap_process_bootstrap_panel(array &$variables) {
119
  $variables['attributes'] = drupal_attributes($variables['attributes']);
120
  $variables['body_attributes'] = drupal_attributes($variables['body_attributes']);
121
  if (!empty($variables['title'])) {
122
    $variables['title'] = filter_xss_admin(render($variables['title']));
123
  }
124
  if (!empty($variables['description'])) {
125
    $variables['description'] = filter_xss_admin(render($variables['description']));
126
  }
127
}