You are here

function date_tools_wizard_create_calendar in Date 7

Same name and namespace in other branches
  1. 6.2 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 385

Code

function date_tools_wizard_create_calendar($name, $bundle, $date_field, $date_instance) {
  $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_' . $bundle, $calendar_options)) {
    unset($calendar_options['calendar_' . $bundle]);
  }
  $option = array(
    'name' => 'calendar_' . $bundle,
    'description' => 'An event calendar for ' . $date_instance['label'],
    'path' => $path,
    'types' => array(
      $bundle => $bundle,
    ),
    'date_fields' => array(
      $date_name,
    ),
    'display_fields' => array(
      'title' => array(),
      $date_name => array(),
    ),
  );
  $calendar_options['calendar_' . $bundle] = $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.
  module_load_include('inc', 'ctools', 'includes/object-cache');
  ctools_object_cache_clear('view', 'calendar_' . $bundle);

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