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
1 string reference to 'media_unsplash_add_submit'
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;
}
}
}