You are here

function media_unsplash_add_submit in Media Unsplash 7

Upload a file from a URL.

This will copy a file from a remote location and store it locally.

See also

media_parse_to_uri()

media_parse_to_file()

1 string reference to 'media_unsplash_add_submit'
media_unsplash_form_file_entity_add_upload_alter in ./media_unsplash.module
Implements hook_form_FORM_ID_alter().

File

./media_unsplash.module, line 469
Provides definition for unsplash media integration.

Code

function media_unsplash_add_submit($form, &$form_state) {
  $embed_code = $form_state['values']['unsplash_code'];
  if (!empty($embed_code)) {
    try {

      // Save the remote file.
      $provider = new MediaUnsplashHandler($embed_code);
      $file = $provider
        ->save();
    } catch (Exception $e) {
      form_set_error('unsplash_code', $e
        ->getMessage());
      return;
    }
    if (!$file->fid) {
      form_set_error('unsplash_code', t('The file %file could not be saved. An unknown error has occurred.', [
        '%file' => $embed_code,
      ]));
      return;
    }
    else {
      $form_state['storage']['upload'] = $file->fid;
    }
  }
}