You are here

function feeds_import_form in Feeds 7.2

Same name and namespace in other branches
  1. 8.2 feeds.pages.inc \feeds_import_form()
  2. 6 feeds.pages.inc \feeds_import_form()
  3. 7 feeds.pages.inc \feeds_import_form()

Render a feeds import form on import/[config] pages.

1 string reference to 'feeds_import_form'
feeds_menu in ./feeds.module
Implements hook_menu().

File

./feeds.pages.inc, line 66
Menu callbacks, form callbacks and helpers.

Code

function feeds_import_form(array $form, array &$form_state, FeedsImporter $importer) {
  $source = feeds_source($importer->id);
  $form['#importer_id'] = $importer->id;

  // @todo Move this into fetcher?
  $form['#attributes']['enctype'] = 'multipart/form-data';
  $form['source_status'] = array(
    '#type' => 'fieldset',
    '#title' => t('Status'),
    '#tree' => TRUE,
    '#value' => feeds_source_status($source),
  );
  $source_form = $source
    ->configForm($form_state);
  if (!empty($source_form)) {
    $form['feeds'] = array(
      '#type' => 'fieldset',
      '#title' => t('Import'),
      '#tree' => TRUE,
    ) + $source_form;
  }

  // Set submit button label based on settings.
  if ($source->importer->config['import_on_create']) {
    $submit = t('Import');
    if ($source->importer->config['process_in_background']) {

      // When processing the import in background, the import job is put in the
      // queue.
      $submit = t('Schedule import');
    }
  }
  elseif ($source->importer->config['import_period'] != FEEDS_SCHEDULE_NEVER) {

    // The import would be scheduled according to the periodic import setting.
    $submit = t('Schedule import');
  }
  else {
    drupal_set_message(t('For this importer both "@import_period" and "@import_on_create" are turned off. It is possible that Feeds will not import the provided source.', array(
      '@import_period' => t('Periodic import'),
      '@import_on_create' => t('Import on submission'),
    )), 'warning', FALSE);
    $submit = t('Save');
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $submit,
  );

  // Disable submit button if import is initiated.
  $progress = $source
    ->progressImporting();
  if ($progress !== FEEDS_BATCH_COMPLETE) {
    $form['actions']['submit']['#disabled'] = TRUE;
    $form['actions']['submit']['#value'] = t('Importing (@progress %)', array(
      '@progress' => number_format(100 * $progress, 0),
    ));

    // Check if import task is queued.
    if ($source
      ->isQueued()) {
      $form['source_status']['#value'] .= t('Run cron to continue the import.');
    }
  }
  return $form;
}