function template_preprocess_views_view_node_fullcalendar in FullCalendar 7
Same name and namespace in other branches
- 6 fullcalendar.module \template_preprocess_views_view_node_fullcalendar()
Prepares variables for template file invoked for node row type.
File
- ./
fullcalendar.module, line 222 - Provides a views style plugin for FullCalendar
Code
function template_preprocess_views_view_node_fullcalendar(&$vars) {
$entity_type = 'node';
if (isset($vars['view']->empty_text)) {
$vars['empty_text'] = $vars['view']->empty_text;
return;
}
$nid = $vars['row']->{$vars['field_alias']};
if (!is_numeric($nid)) {
return;
}
$node = node_load($nid);
if (empty($node)) {
return;
}
// Allow resize/drag/drop of an event if user has proper permissions.
$node->editable = _fullcalendar_update_access($node);
$node->class = theme('fullcalendar_classname', array(
'node' => $node,
));
$vars['node'] = $node;
$vars['data'] = array();
// Contains the start, end & allDay values.
$node->url = 'node/' . $nid;
if ($url_field = $vars['options']['fullcalendar_url_field']) {
if ($url_field = field_get_items('node', $node, $url_field)) {
$vars['url'] = $url_field[0]['value'];
}
}
$title_field = $vars['options']['fullcalendar_title_field'];
if (!empty($title_field) && !empty($node->{$title_field}[0]['value'])) {
$node->title = $node->{$title_field}[0]['value'];
}
$display_field = fullcalendar_date_fields($node);
$field_names = trim(strip_tags($vars['options']['fullcalendar_date_fields']));
if (!empty($field_names)) {
foreach (explode("\n", $field_names) as $field_name) {
$field_name = trim(strip_tags($field_name));
if ($field_name == 'created' || $field_name == 'changed') {
$attributes = _fullcalendar_set_display_times($entity_type, $node, $field_name);
$vars['data'][] = theme('fullcalendar_link', array(
'node' => $node,
'attributes' => $attributes,
'index' => 0,
));
$display_field = array();
break;
}
// If a date_type field exists
if (isset($display_field[$field_name])) {
$display_field = array(
$field_name => $display_field[$field_name],
);
break;
}
}
}
// Iterate through available fields, using the first one found.
foreach ($display_field as $field_name => $field) {
$instance = field_info_instance($entity_type, $field_name, $node->type);
$items = field_get_items($entity_type, $node, $field_name);
if (!empty($items)) {
foreach ($items as $index => $item) {
$vars['data'][] = theme('fullcalendar_link', array(
'node' => $node,
'attributes' => _fullcalendar_set_display_times($entity_type, $node, $field_name, $instance, $field, $item),
'index' => $index,
));
}
}
break;
}
}