Newer
Older
Benjamin J Doherty
committed
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
// $Id$
/**
* @file semanticviews.module
* TODO: Enter file description here.
*/
/**
* Implementation of hook_views_api().
*/
function semanticviews_views_api() {
return array(
'api' => 2.0,
);
}
/**
* Preprocess theme function to print a single record from a row, with fields
*/
function template_preprocess_semanticviews_view_fields(&$variables) {
$view = $variables['view'];
// Loop through the fields for this view.
$variables['fields'] = array(); // ensure it's at least an empty array.
foreach ($view->field as $id => $field) {
// render this even if set to exclude so it can be used elsewhere.
$field_output = $view->field[$id]->theme($variables['row']);
if (empty($field->options['exclude'])) {
$object = new stdClass();
$object->content = $field_output;
if (isset($view->field[$id]->field_alias) && isset($variables['row']->{$view->field[$id]->field_alias})) {
$object->raw = $variables['row']->{$view->field[$id]->field_alias};
}
else {
$object->raw = NULL; // make sure it exists to reduce NOTICE
}
$object->handler = &$view->field[$id];
$semantic_html = $variables['options']['semantic_html'][$id];
$object->element_type = check_plain($semantic_html['element_type']);
$object->attributes = array();
if ($semantic_html['class']) {
$object->attributes['class'] = $semantic_html['class'];
}
$object->label = check_plain($view->field[$id]->label());
$variables['fields'][$id] = $object;
}
}
}
/**
* Display the simple view of rows one after another
*/
function template_preprocess_semanticviews_view_unformatted(&$variables) {
$variables['group_element'] = check_plain($variables['options']['group']['element_type']);
$variables['group_attributes'] = array();
if ($variables['options']['group']['class']) {
$variables['group_attributes']['class'] = $variables['options']['group']['class'];
}
// TODO: set a default or handle empty value.
$variables['row_element'] = check_plain($variables['options']['row']['element_type']);
$last_every_nth = $variables['options']['last_every_nth'];
$variables['row_attributes'] = array();
foreach ($variables['rows'] as $id => $row) {
$variables['row_attributes'][$id] = array();
$classes = array();
if ($variables['options']['row']['class']) {
$classes[] = str_replace('#', $id, $variables['options']['row']['class']);
}
if ($id == 0 && $variables['options']['row']['first_class']) {
$classes[] = $variables['options']['row']['first_class'];
}
if (($last_every_nth && ($id + 1) % $last_every_nth == 0) ||
(!$last_every_nth && $id == count($variables['rows']))) {
$classes[] = $variables['options']['row']['last_class'];
}
// TODO: implement configurable row striping
//$classes[] = $id % 2 ? 'even' : 'odd';
if (!empty($classes)) {
$variables['row_attributes'][$id]['class'] = implode(' ', $classes);
}
}
}
function semanticviews_theme_registry_alter(&$theme_registry) {
if (isset($theme_registry['views_view'])) {
// Add the module's path to the theme paths.
if (isset($theme_registry['views_view']['theme paths'])) {
$module_path = drupal_get_path('module', 'semanticviews');
array_push($theme_registry['views_view']['theme paths'], $module_path);
}
// Add an additional preprocess function to the theme info.
if (isset($theme_registry['views_view']['preprocess functions'])) {
$module_path = drupal_get_path('module', 'semanticviews');
array_push($theme_registry['views_view']['preprocess functions'], 'template_preprocess_semanticviews_view');
}
}
}
/**
* The class attributes of the outer div of a View cannot be changed when the
* view uses AJAX. The Views ajax scripts need these classes to attach
* behaviors.
* - view-dom-id-%
* OR
* - view-id-% and view-display-id-%
*
* @see template_preprocess_views_view
* @see ajax_view.js
*
* @param <type> $variables
*/
function template_preprocess_semanticviews_view(&$variables) {
if ($variables['view']->plugin_name == 'semanticviews_default') {
$variables['template_file'] = 'semanticviews-view';
$variables['attributes'] = array();
// Container class attributes are stacked in an array.
$classes = array();
// TODO: Bring class attribute into UI for configuration.
//$classes[] = 'view';
if ($variables['view']->use_ajax) {
// The old way Ajax Views were selected for behaviors.
//$classes[] = 'view-'. $variables['css_name'];
//$classes[] = 'view-id-'. $variables['name'];
//$classes[] = 'view-display-id-'. $variables['display_id'];
// The new way.
$classes[] = 'view-dom-id-'. $variables['dom_id'];
}
if (!empty($classes)) {
$variables['attributes']['class'] = implode(' ', $classes);
}
if ($variables['view']->style_options['id']) {
// TODO: Prevent ID collision. Or not?
$variables['attributes']['id'] = $variables['view']->style_options['id'];
}
}
}