-
Notifications
You must be signed in to change notification settings - Fork 6
/
field_group.theme.inc
133 lines (116 loc) · 4.4 KB
/
field_group.theme.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* @file
* Theme functions for field groups.
*/
/**
* Returns HTML for an element's children fieldsets as horizontal tabs.
*
* @param array $variables
* An associative array containing:
* - element: An associative array containing the properties and children of the
* fieldset. Properties used: #children.
*
* @return string
* HTML output.
*
* @ingroup themeable
*/
function theme_horizontal_tabs($variables) {
$element = $variables['element'];
// Add required JavaScript and Stylesheet.
backdrop_add_library('field_group', 'horizontal-tabs');
$output = '<h2 class="element-invisible">' . (!empty($element['#title']) ? $element['#title'] : t('Horizontal Tabs')) . '</h2>';
$output .= '<div class="horizontal-tabs-panes">' . $element['#children'] . '</div>';
return $output;
}
/**
* Returns HTML for an element's children fieldsets as multipage.
*
* @param array $variables
* An associative array containing:
* - element: An associative array containing the properties and children of the
* fieldset. Properties used: #children.
*
* @return string
* HTML output.
*
* @ingroup themeable
*/
function theme_multipage($variables) {
$element = $variables['element'];
// Add required JavaScript and Stylesheet.
$element['#attached']['library'][] = array('field_group', 'multipage');
$output = '<h2 class="element-invisible">' . (!empty($element['#title']) ? $element['#title'] : t('Multipage')) . '</h2>';
$output .= '<div class="multipage-panes">';
$output .= $element['#children'];
$output .= '</div>';
return $output;
}
/**
* Returns HTML for multipage pane.
*
* @param $variables
* An associative array containing:
* - element: An associative array containing the properties and children of the
* fieldset. Properties used: #children.
*
* @return string
* HTML output.
*
* @ingroup themeable
*/
function theme_multipage_pane($variables) {
$element = $variables['element'];
$group = $variables['element']['#group_object'];
$parent_group = $variables['element']['#parent_group_object'];
static $multipages;
if (!isset($multipages[$group->parent_name])) {
$multipages = array($group->parent_name => 0);
}
$multipages[$parent_group->group_name]++;
// Create a page title from the label.
$page_header = isset($parent_group->format_settings['instance_settings']['page_header']) ? $parent_group->format_settings['instance_settings']['page_header'] : 3;
switch ($page_header) {
case 1:
$title = $element['#title'];
break;
case 2:
$title = t('Step %count of %total', array('%count' => $multipages[$parent_group->group_name], '%total' => count($parent_group->children)));
break;
case 3:
$title = t('Step %count of %total !label', array('%count' => $multipages[$parent_group->group_name], '%total' => count($parent_group->children), '!label' => $element['#title']));
break;
case 0:
default:
$title = '';
break;
}
element_set_attributes($element, array('id'));
_form_set_class($element, array('form-wrapper'));
$output = '<div' . backdrop_attributes($element['#attributes']) . '>';
if (!empty($element['#title'])) {
// Always wrap fieldset legends in a SPAN for CSS positioning.
$output .= '<h2 class="multipage-pane-title"><span>' . $title . '</span></h2>';
}
$output .= '<div class="fieldset-wrapper multipage-pane-wrapper">';
if (!empty($element['#description'])) {
$output .= '<div class="fieldset-description">' . $element['#description'] . '</div>';
}
$output .= $element['#children'];
if (isset($element['#value'])) {
$output .= $element['#value'];
}
// Add a page counter if needed.
// counter array(0 => t('No'), 1 => t('Format 1 / 10'), 2 => t('The count number only'));
$page_counter_format = isset($parent_group->format_settings['instance_settings']['page_counter']) ? $parent_group->format_settings['instance_settings']['page_counter'] : 1;
$multipage_element['#page_counter_rendered'] = '';
if ($page_counter_format == 1) {
$output .= t('<span class="multipage-counter">%count / %total</span>', array('%count' => $multipages[$parent_group->group_name], '%total' => count($parent_group->children)));
} elseif ($page_counter_format == 2) {
$output .= t('<span class="multipage-counter">%count</span>', array('%count' => $multipages[$parent_group->group_name]));
}
$output .= '</div>';
$output .= "</div>\n";
return $output;
}