You are here

function media_youtube_add_submit in Media: YouTube 7.2

@TODO: Document this function.

File

./media_youtube.module, line 306
Provides a stream wrapper and formatters appropriate for accessing and displaying YouTube videos.

Code

function media_youtube_add_submit($form, &$form_state) {
  $uri = $form_state['values']['submitted-video'];
  try {

    // Save the remote file
    $file = file_uri_to_object($uri, TRUE);
    file_save($file);
  } catch (Exception $e) {
    form_set_error('url', $e
      ->getMessage());
    return;
  }
  if (!$file->fid) {
    form_set_error('url', t('The file %file could not be saved. An unknown error has occurred.', array(
      '%file' => $uri,
    )));
    return;
  }
  else {
    $form_state['file'] = $file;
  }

  // Redirect to the file edit page after submission.
  if (media_youtube_access('update', $file)) {
    $destination = array(
      'destination' => 'admin/content/file',
    );
    if (isset($_GET['destination'])) {
      $destination = drupal_get_destination();
      unset($_GET['destination']);
    }
    $form_state['redirect'] = array(
      'file/' . $file->fid . '/edit',
      array(
        'query' => $destination,
      ),
    );
  }
  else {
    $form_state['redirect'] = 'admin/content/file';
  }
}