You are here

function date_tools_wizard_build in Date 7

Same name and namespace in other branches
  1. 8 date_tools/date_tools.wizard.inc \date_tools_wizard_build()
  2. 6.2 date_tools/date_tools.wizard.inc \date_tools_wizard_build()
  3. 7.3 date_tools/date_tools.wizard.inc \date_tools_wizard_build()
  4. 7.2 date_tools/date_tools.wizard.inc \date_tools_wizard_build()
1 call to date_tools_wizard_build()
date_tools_wizard_form_submit in date_tools/date_tools.wizard.inc

File

date_tools/date_tools.wizard.inc, line 156

Code

function date_tools_wizard_build($form_values) {
  extract($form_values);
  $field_name = 'field_' . $field_name;
  if (!empty($repeat)) {
    $widget_type .= '_repeat';
  }

  // Create a node type if it doesn't already exist.
  // This makes it possible to add additional date fields to
  // an existing type.
  $types = node_type_get_names();
  $type_settings = array();
  if (!array_key_exists($bundle, $types)) {
    date_tools_wizard_create_content_type($name, $bundle, $type_description, $type_settings);
    drupal_set_message(t('Your content type @name has been created.', array(
      '@name' => $name,
    )));
  }
  else {
    $types = node_type_get_types();
    $type = $types[$bundle];
    if (!empty($type_settings)) {
      foreach ($type_settings as $key => $setting) {
        $type->{$key} = $setting;
      }
      node_type_save($type);
    }
    $name = $type->name;
  }
  $field = array(
    'field_name' => $field_name,
    'type' => $field_type,
    'cardinality' => $repeat ? FIELD_CARDINALITY_UNLIMITED : 1,
    'settings' => array(
      'granularity' => $granularity,
      'tz_handling' => $tz_handling,
      'timezone_db' => date_get_timezone_db($tz_handling),
      'repeat' => $repeat,
      'todate' => !empty($todate) ? $todate : 'optional',
    ),
  );
  $instance = array(
    'entity_type' => 'node',
    'field_name' => $field_name,
    'label' => $label,
    'bundle' => $bundle,
    // Move the date right below the title.
    'weight' => -4,
    'widget' => array(
      'type' => $widget_type,
      // Increment for minutes and seconds, can be 1, 5, 10, 15, or 30.
      'settings' => array(
        'increment' => 15,
        // The number of years to go back and forward in drop-down year selectors.
        'year_range' => !empty($year_range) ? $year_range : '-0:+1',
        'input_format' => date_default_format($widget_type),
        'text_parts' => array(),
        'label_position' => 'above',
        'repeat_collapsed' => 0,
      ),
      'weight' => -4,
    ),
    'settings' => array(
      'default_value' => 'now',
      'default_value2' => 'blank',
      'default_format' => 'long',
    ),
  );
  $instance['display'] = array(
    'default' => array(
      'label' => 'above',
      'type' => 'date_default',
      'settings' => array(
        'format_type' => 'long',
        'show_repeat_rule' => 'show',
        'multiple_number' => '',
        'multiple_from' => '',
        'multiple_to' => '',
        'fromto' => 'both',
      ),
      'module' => 'date',
      'weight' => 0,
    ),
    'teaser' => array(
      'label' => 'above',
      'type' => 'date_default',
      'weight' => 0,
      'settings' => array(
        'format_type' => 'long',
        'show_repeat_rule' => 'show',
        'multiple_number' => '',
        'multiple_from' => '',
        'multiple_to' => '',
        'fromto' => 'both',
      ),
      'module' => 'date',
    ),
  );
  $field = field_create_field($field);
  $instance = field_create_instance($instance);

  //_field_info_collate_fields(TRUE);
  field_info_cache_clear(TRUE);
  field_cache_clear(TRUE);
  $view_name = '';
  if (!empty($calendar) && module_exists('calendar')) {
    $view_name = date_tools_wizard_create_calendar($name, $bundle, $field, $instance);
    if (!empty($blocks)) {
      date_tools_wizard_create_blocks($bundle, $blocks);
    }
  }

  // Update the menu router information.
  menu_rebuild();
  drupal_set_message(t('Your date field @name has been created.', array(
    '@name' => $label,
  )));
  return $view_name;
}