You are here

function calendar_views_templates in Calendar 7.3

Implements hook_views_templates().

File

includes/calendar.views_template.inc, line 14
View templates for the Calendar module.

Code

function calendar_views_templates() {
  $views = array();
  if (!variable_get('calendar_provide_views_templates', 1)) {
    return $views;
  }

  // Map the base tables to entity types.
  $entity_info = entity_get_info();
  $base_tables = date_views_base_tables();
  $with_ical = module_exists('date_ical');

  // Find all the date fields we know about.
  $processed = array();
  foreach ($entity_info as $entity_type => $info) {
    if (!$info['fieldable']) {
      continue;
    }
    $items = field_info_instances($entity_type);
    $views_fields = date_views_fields($info['base table']);
    $with_colorbox = $entity_type == 'node' && module_exists('colorbox') && variable_get('calendar_add_colorbox', 0);
    foreach ($views_fields['name'] as $name => $data) {

      // For each of the Field date fields, we need to find the bundle and entities this field is used on.
      if ($data['is_field']) {
        foreach ($items as $bundle => $widgets) {
          foreach ($widgets as $field_name => $widget) {
            $field = field_info_field($field_name);

            // See if this is a date field. Since fields might be shared
            // across bundles, make sure we haven't already processed this field.
            // $alias = 'field_data_' . $field_name . '.' . $field_name . '_value';
            // $alias will not work because $alias can be from multiple base_tables
            // and we would not want to exclude a field from other base tables because
            // it was used in one.
            // Limiting the fields to date fields will make this loop more efficient
            if ($field['module'] == 'date') {
              $base_table = $info['base table'];
              $calendar_option = array(
                'name' => 'calendar_' . $base_table . '_' . $field_name,
                'description' => t("A calendar view of the '@field_name' field in the '@base_table' base table.", array(
                  '@base_table' => $base_table,
                  '@field_name' => $field_name,
                )),
                'path' => str_replace('_', '-', 'calendar-' . $base_table . '-' . $field_name),
                'base_table' => $base_table,
                'field_name' => $field_name,
                'with_colorbox' => $with_colorbox,
                'with_ical' => $with_ical,
              );
              $view = calendar_views_template_construct($calendar_option);
              $views[$view->name] = $view;
            }
          }
        }
      }
      else {
        $parts = explode('.', $name);
        $base_table = $parts[0];
        $field_name = $parts[1];
        $calendar_option = array(
          'name' => 'calendar_' . $entity_type . '_' . $field_name,
          'description' => t("A calendar view of the '@field_name' field in the '@base_table' base table.", array(
            '@base_table' => $base_table,
            '@field_name' => $field_name,
          )),
          'path' => 'calendar-' . str_replace('_', '-', $field_name),
          'base_table' => $base_table,
          'field_name' => $field_name,
          'with_colorbox' => $with_colorbox,
          'with_ical' => $with_ical,
        );
        $view = calendar_views_template_construct($calendar_option);
        $views[$view->name] = $view;
      }
    }
  }
  return $views;
}