You are here

function date_tools_copy_type_form in Date 6.2

A form to select a content type.

1 call to date_tools_copy_type_form()
date_tools_copy_import_event_form in date_tools/date_tools.event.inc
Event import form.

File

date_tools/date_tools.event.inc, line 271
Code to migrate Events to use Date fields instead.

Code

function date_tools_copy_type_form($target = TRUE) {
  $form = array();
  $node_types = node_get_types('names');
  $fields = content_fields();
  $type_options = array();

  // Find out what content types contain date fields and set them up as target options.
  foreach ($fields as $field_name => $field) {
    if ($field['type'] == 'date' || $field['type'] == 'datestamp' || $field['type'] == 'datetime') {
      $type_options[$field['type_name']] = $node_types[$field['type_name']];
    }
  }
  if (sizeof($type_options) < 1) {
    drupal_set_message(t('There are no date fields in this database to import the data into. Please add a date field to the desired node types and be sure to indicate it uses both a "from" and a "to" date.'));
    return $form;
  }
  $type = $target ? 'target_type' : 'source_type';
  $label = $target ? t('Target type') : t('Source type');
  $form[$type] = array(
    '#type' => 'select',
    '#options' => $type_options,
    '#title' => $label,
    '#description' => t('Only content types with date fields appear in this list as possible target types.'),
    '#default_value' => '',
  );

  // If Content Copy is enabled, offer an import link.
  if (module_exists('content_copy')) {
    $form['macro'] = array(
      '#type' => 'fieldset',
      '#title' => t('Add'),
      '#description' => t('If your desired target type does not already have a date field, follow this link and select a content type to add a date field to that type.'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['macro']['link'] = array(
      '#type' => 'markup',
      '#value' => l(t('Add new date field'), 'admin/content/types/import', array(
        'query' => 'macro_file=' . drupal_get_path('module', 'date_tools') . '/date_field.php',
      )),
    );
  }
  return $form;
}