You are here

function date_tools_wizard_create_calendar in Date 6.2

Same name and namespace in other branches
  1. 7 date_tools/date_tools.wizard.inc \date_tools_wizard_create_calendar()
1 call to date_tools_wizard_create_calendar()
date_tools_wizard_build in date_tools/date_tools.wizard.inc

File

date_tools/date_tools.wizard.inc, line 448
Date Wizard code.

Code

function date_tools_wizard_create_calendar($name, $type_name, $date_field) {
  $date_name = !empty($date_field) ? $date_field['field_name'] : '';
  $path = 'calendar-' . str_replace('field_', '', $date_name);

  // Add a default calendar for this content type.
  $calendar_options = variable_get('calendar_default_view_options', array());
  if (array_key_exists('calendar_' . $type_name, $calendar_options)) {
    unset($calendar_options['calendar_' . $type_name]);
  }
  $option = array(
    'name' => 'calendar_' . $type_name,
    'description' => 'An event calendar for ' . $date_field['widget']['label'],
    'path' => $path,
    'types' => array(
      $type_name => $name,
    ),
    'date_fields' => array(
      $date_name,
    ),
    'display_fields' => array(
      'title' => array(),
      $date_name => array(),
    ),
  );
  $calendar_options['calendar_' . $type_name] = $option;
  variable_set('calendar_default_view_options', $calendar_options);

  // Make sure menu items get rebuilt as necessary.
  menu_rebuild();

  // Clear the views cache.
  cache_clear_all('*', 'cache_views');

  // Clear the page cache.
  cache_clear_all();

  // Remove this view from cache so we can edit it properly.
  views_object_cache_clear('view', 'calendar_' . $type_name);

  // Force Views to empty its cache and find the new view.
  views_discover_default_views();
  return 'calendar_' . $type_name;
}