You are here

function atom_reference_field_presave in Scald: Media Management made easy 7

Implements hook_field_presave().

File

modules/fields/atom_reference/atom_reference.module, line 131
Defines a new field type, allowing to directly reference Scald Atoms from a node.

Code

function atom_reference_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
  foreach ($items as $delta => $item) {
    if (empty($item['sid'])) {
      continue;
    }
    $options = array();
    if (!empty($item['options'])) {
      $options = unserialize($item['options']);
    }
    foreach ($item as $name => $option) {
      if ($name == 'sid' || $name == 'options') {
        continue;
      }
      if (!empty($item[$name])) {
        $options[$name] = $option;
      }
      else {
        unset($options[$name]);
      }
    }
    $items[$delta]['options'] = serialize($options);
  }
}