You are here

function template_preprocess_views_view_node_fullcalendar in FullCalendar 6

Same name and namespace in other branches
  1. 7 fullcalendar.module \template_preprocess_views_view_node_fullcalendar()

Prepares variables for template file invoked for node row type.

File

./fullcalendar.module, line 213
Provides a views style plugin for FullCalendar

Code

function template_preprocess_views_view_node_fullcalendar(&$vars) {
  if (isset($vars['view']->empty)) {
    $vars['empty_text'] = $vars['view']->empty;
    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', $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 (isset($node->{$url_field}[0]['value'])) {
      $node->url = $node->{$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($node, $field_name);
        $vars['data'][] = theme('fullcalendar_link', $node, $attributes);
        $display_field = array();
        break;
      }

      // If a date_type field exists
      if ($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) {
    foreach ($node->{$field_name} as $index => $item) {
      $attributes = _fullcalendar_set_display_times($node, $field_name, $field, $item);
      $vars['data'][] = theme('fullcalendar_link', $node, $attributes, $index);
    }
    break;
  }
}