You are here

function emimport_import_submit in Embedded Media Field 5

This will import the selected set items as new nodes.

TODO: create a cron loop to handle overflow when a lot of nodes are selected, so we don't time out.

File

contrib/emimport/emimport.module, line 446

Code

function emimport_import_submit($form_id, $form_values) {
  global $user;
  if ($form_values['op'] == t('Import')) {
    foreach ($form_values['info'] as $field_name => $field_info) {
      $module = $field_info['codes']['#module'];

      // TODO: doesn't look like we need that in this step...
      $provider = $field_info['codes']['#provider'];
      $codes = $field_info['codes']['#codes'];
      $set = $field_info['codes']['#set'];

      // TODO: looks like this is also not needed, actually called directly in loop
      $tags_vid = $field_info['codes']['#vid'];
      $type = $field_info['codes']['#content_type'];
      foreach ($codes['#set'] as $item) {

        // process only if we've checked the box next to the thumbnail
        if ($form_values[$field_name . '_code_' . $item['#code']]) {
          $info = array(
            '#type' => $type,
            '#account' => $user,
            '#field_name' => $field_name,
            '#provider' => $provider,
            '#tags_vid' => $tags_vid,
            '#title' => $form_values[$field_name . '_title_' . $item['#code']],
            '#body' => $form_values[$field_name . '_body_' . $item['#code']],
            '#original_link' => $form_values[$field_name . '_link_' . $item['#code']],
            '#code' => $item['#code'],
            '#tags' => $form_values[$field_name . '_tags_' . $item['#code']],
          );
          emimport_save_info_for_processing($info);
        }
      }
    }
    return 'emimport/' . $type;
  }
  else {
    if ($form_values['op'] == t('Cancel')) {
      return 'emimport/' . arg(1);

      // TODO: hack; i forget where i set the type in the form
    }
  }
}