You are here

function panopoly_widgets_field_presave in Panopoly Widgets 7

Implements hook_field_presave()

File

./panopoly_widgets.spotlight.inc, line 363
A specification for the custom spotlight entity that is part of Panopoly Widgets

Code

function panopoly_widgets_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {

  // We need to set presave values if fids are not set. This shouldn't effect save operations
  // form API validation will prevent this from ever happening unless previewing.
  if (!empty($items)) {
    foreach ($items as &$item) {
      if (empty($item['fid'])) {
        $fid = variable_get('panopoly_widgets_default_' . $entity->bundle . '_fid', NULL);
        if (!empty($fid)) {
          $item['fid'] = $fid;
        }
      }
      if (isset($item['field_title'])) {
        $item['title'] = $item['field_title'];
      }
      if (isset($item['field_alt'])) {
        $item['alt'] = $item['field_alt'];
      }
    }
    image_field_presave($entity_type, $entity, $field, $instance, $langcode, $items);
  }
}