You are here

function gathercontent_import_content_type in GatherContent 7

Import wizard step 1: Select content type.

1 string reference to 'gathercontent_import_content_type'
gathercontent_import in ./gathercontent.module
Import wizard, built with CTools multistep form wizard.

File

./gathercontent.module, line 212
Imports pages from GatherContent (http://gathercontent.com/) into Drupal as nodes.

Code

function gathercontent_import_content_type($form, &$form_state) {
  $account_name = variable_get('gathercontent_account_name');
  $api_key = variable_get('gathercontent_api_key');
  $project_id = variable_get('gathercontent_project_id');

  // Build an array of available GatherContent projects, if any.
  $projects = gathercontent_get_command('get_projects');
  $projects_list = gathercontent_projects_list($projects);
  if (empty($account_name) || empty($api_key)) {
    drupal_set_message(t('Please <a href="/admin/config/content/gathercontent/settings">enter your GatherContent account name and API key</a> before continuing.'), 'warning', FALSE);
  }
  if (!empty($account_name) && !empty($api_key)) {
    if (isset($projects->success) && $projects->success == TRUE) {
      if (empty($project_id) || !array_key_exists($project_id, $projects_list)) {
        drupal_set_message(t('Please <a href="/admin/config/content/gathercontent/settings">select one of your available GatherContent projects</a> before continuing.'), 'warning', FALSE);
      }
    }
    elseif (isset($projects->is_error) && $projects->is_error == TRUE) {
      drupal_set_message(t('It looks like you didn\'t configure any GatherContent projects yet. <a href="@gc_link">Please do so first</a>, then <a href="/admin/config/content/gathercontent/settings">select it here</a> before continuing with your import.', array(
        '@gc_link' => 'https://' . $account_name . '.gathercontent.com/',
      )), 'warning', FALSE);
    }
  }
  $content_types = array();
  $available_content_types = node_type_get_types();
  foreach ($available_content_types as $type => $info) {
    $content_types[$type] = $info->name;
  }
  asort($content_types);
  $content_type = variable_get('gathercontent_content_type');
  $form['gathercontent_content_type'] = array(
    '#title' => t("Select content type."),
    '#description' => t("Select the content type of which you want to create nodes. By default, your GatherContent page content will be imported into the new node's body field, so make sure your content type has a body field. You can override this default behaviour by implementing hook_gathercontent_presave()."),
    '#type' => 'select',
    '#default_value' => $content_type == '' ? 'all' : $content_type,
    '#options' => $content_types,
    '#required' => TRUE,
  );
  return $form;
}