function emfield_widget_validate in Embedded Media Field 7
Validation callback for an emfield element.
1 string reference to 'emfield_widget_validate'
- emfield_field_widget_form in ./
emfield.module - Implements hook_field_widget_form().
File
- ./
emfield.module, line 66
Code
function emfield_widget_validate($element, &$form_state, $form) {
$field = field_widget_field($element, $form_state);
$instance = field_widget_instance($element, $form_state);
$value = $element['#value'];
$fid = NULL;
if (!empty($value)) {
// Get the fid of a referencable file from the entered url.
try {
$provider = media_internet_get_provider($value);
} catch (Exception $error) {
form_error($element, t('%name: Found no valid media with that url.', array(
'%name' => $instance['label'],
)));
return;
}
$file = $provider
->save();
$fid = $file->fid;
}
// Set the element's value as the file id that was extracted from the entered
// input.
form_set_value($element, $fid, $form_state);
}