function text_field_insert in Scald: Media Management made easy 7
Implements hook_field_insert() on behalf of Text module.
See also
File
- modules/
fields/ mee/ mee.module, line 287 - Defines a special textarea, with drag and drop media driven by Scald and dnd.module.
Code
function text_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
if (!_mee_field_instance_enabled($instance, 'mee')) {
return;
}
list($id, $revision_id) = _mee_extract_id($entity_type, $entity);
foreach ($items as $delta => $item) {
list($sids, $copyrights) = _mee_process_item_value($item, $entity_type, $entity, $field, $delta);
// Normalize the weight, putting our separator at 0.
$separator = $item['mee']['resource_manager'][0]['weight'];
foreach ($sids as $sid) {
$resource = $item['mee']['resource_manager'][$sid];
db_insert('mee_resource')
->fields(array(
'entity_type' => $entity_type,
'entity_id' => $id,
'revision_id' => $revision_id,
'atom_sid' => $sid,
'field' => $field['field_name'],
'delta' => $delta,
'weight' => $resource['weight'] - $separator,
'required' => (int) $resource['required'],
'copyright' => isset($copyrights[$sid]) ? $copyrights[$sid] : '',
))
->execute();
}
}
}