function scald_file_scald_add_form_fill in Scald File Provider 7
Implements hook_scald_add_form_fill().
File
- ./
scald_file.module, line 73 - Scald File is a Scald Atom Provider for Files.
Code
function scald_file_scald_add_form_fill(&$atoms, $form, $form_state) {
foreach ($atoms as $delta => $atom) {
if (is_array($form_state['values']['file']) && module_exists('plupload')) {
module_load_include('inc', 'scald', 'includes/scald.plupload');
$destination = $form['file']['#upload_location'] . '/' . $form_state['values']['file'][$delta]['name'];
$file = scald_plupload_save_file($form_state['values']['file'][$delta]['tmppath'], $destination);
}
else {
$file = file_load($form_state['values']['file']);
}
foreach (array(
'author',
'tag',
) as $name) {
// hacky, because variable and field name do not really match.
$field_name = 'scald_' . $name . 's';
$langcode = field_language('scald_atom', $atom, $field_name);
if (empty($form_state['values'][$field_name])) {
continue;
}
// Borrowed from taxonomy_autocomplete_validate().
$typed_terms = drupal_explode_tags($form_state['values'][$field_name]);
$vocabulary = taxonomy_vocabulary_machine_name_load(variable_get('scald_' . $name . '_vocabulary', $field_name));
foreach ($typed_terms as $typed_term) {
if ($possibilities = taxonomy_term_load_multiple(array(), array(
'name' => trim($typed_term),
'vid' => $vocabulary->vid,
))) {
$term = array_pop($possibilities);
}
else {
$term = (object) array(
'vid' => $vocabulary->vid,
'name' => $typed_term,
'vocabulary_machine_name' => $vocabulary->machine_name,
);
taxonomy_term_save($term);
}
$atom->{$field_name}[$langcode][] = array(
'tid' => $term->tid,
);
}
}
$atom->title = $file->filename;
$langcode = field_language('scald_atom', $atom, 'scald_file');
$atom->scald_file[$langcode][0] = (array) $file;
}
}