You are here

function bynder_upload_submit in Bynder 7

File

includes/bynder_upload.inc, line 102

Code

function bynder_upload_submit($form, &$form_state) {

  // We need to check whether this is the Media browser overlay or the page because for some reason the oauth login form
  // submits the upload form when returning from Bynder.
  if (!isset($_SESSION['bynder_oauth_login'])) {
    $files = $_SESSION[$form_state['values']['bynder_form_token']];
    if (isset($files)) {
      $batchOperations = array();
      $totalFiles = count($files);
      foreach ($files as $file) {
        $batchOperations[] = array(
          'bynder_upload_file_batch',
          array(
            $file,
          ),
        );
        $batchOperations[] = array(
          'bynder_upload_delete_tmp_files',
          array(),
        );
        $batchOperations[] = array(
          'bynder_upload_add_to_library',
          array(),
        );
      }
      $batch = array(
        'operations' => $batchOperations,
        'finished' => 'bynder_upload_file_batch_finished',
        'title' => t('Batch to upload files to Bynder'),
        'init_message' => t('Bynder upload process is starting...'),
        'progress_message' => t('Processed @current out of @totalFiles.', array(
          '@totalFiles' => $totalFiles,
        )),
        'error_message' => t('Import has encountered an error.'),
      );

      // If we're in a popup
      if (current_path() == BYNDER_MEDIA_UPLOAD_URL) {
        $_SESSION['bynder_upload_browser'] = 'library';
      }
      batch_set($batch);
    }
  }
  unset($_SESSION['bynder_oauth_login']);
}