/
template.php
executable file
·108 lines (96 loc) · 3.33 KB
/
template.php
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
<?php
/**
* @file
* template.php
*/
// Load all theme includes
$theme_path = drupal_get_path('theme', 'bunsen');
$files = file_scan_directory($theme_path . '/preprocess', '/.php/');
foreach ($files as $filepath => $file) {
require_once($filepath);
}
/*
* Implements hook_form_alter().
*/
function bunsen_form_alter(&$form, &$form_state, $form_id){
$form_type = !empty($form['type']['#value']) ? $form['type']['#value'] : '';
$form['#attributes']['class'][] = 'form-horizontal';
// Add icons to action buttons
$form['actions']['submit']['#value'] .= ' <i class="fa fa-save"></i>';
if(!empty($form['actions']['delete'])){
$form['actions']['delete']['#value'] .= ' <i class="fa fa-ban"></i>';
}
// Remove node settings at the bottom of form
unset($form['additional_settings']);
foreach($form as $key => $element){
if (is_array($form[$key]) && isset($form[$key]['#group'])) {
unset($form[$key]);
}
// Wrap certain form element types with Bootstrap column classes
if(strrpos($key, 'field_', -strlen($key)) !== FALSE || $key == 'title'){
$field_info = field_info_instance('node', $key, $form_type);
$field_type = !empty($field_info['widget']['type']) ? $field_info['widget']['type'] : '';
$column_prefix = '<span class="col-md-8">';
$column_suffix = '</span>';
$adjust_col = FALSE;
if($key == 'title'){
$form_elem = &$form[$key];
$adjust_col = TRUE;
}
else{
switch($field_type){
case "text_textarea":
break;
case "file_generic":
$form_elem = &$form[$key][LANGUAGE_NONE][0];
$adjust_col = TRUE;
break;
case "number":
$form_elem = &$form[$key][LANGUAGE_NONE][0]['value'];
$column_prefix = '<span class="col-md-2 input-type-number">';
$adjust_col = TRUE;
break;
case "text_textfield":
$form_elem = &$form[$key][LANGUAGE_NONE][0]['value'];
$adjust_col = TRUE;
break;
default:
$form_elem = &$form[$key][LANGUAGE_NONE];
$adjust_col = TRUE;
break;
}
}
if($adjust_col){
$prefix = !empty($form_elem['#field_prefix']) ? $form_elem['#field_prefix'] : '';
$suffix = !empty($form_elem['#field_suffix']) ? $form_elem['#field_suffix'] : '';
$form_elem['#field_prefix'] = $column_prefix . $prefix;
$form_elem['#field_suffix'] = $suffix . $column_suffix;
}
}
}
}
/**
* Implements hook_field_group_pre_render_alter().
*/
function bunsen_field_group_pre_render_alter(&$element, $group, &$form) {
$key = '';
if(!empty($group->group_name)){
$key = $group->group_name;
// Add class to top-level field groups
if(!empty($form[$key])){
$form[$key]['#attributes']['class'][] = 'field-group-parent';
}
}
if($element['#type'] == 'fieldset' && !isset($element['#id'])){
$element['#id'] = drupal_html_id('fieldset');
}
}
function bunsen_theme(){
$items = array();
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'bunsen') . '/templates',
'template' => 'user-login',
);
return $items;
}