You are here

function download_field_presave in Download 7.2

Same name and namespace in other branches
  1. 7 download.module \download_field_presave()

File

./download.module, line 205
Handles module administration and download link

Code

function download_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
  $tmp_items = $items;
  $items = NULL;
  foreach ($tmp_items as $key => $item) {
    if (isset($item['download_fields'])) {
      $fields = '';

      // When saving with widget, transform array with download_fields to string
      if (is_array($item['download_fields'])) {
        foreach ($item['download_fields'] as $fieldname => $value) {
          if ($value != '0') {
            $fields .= $fieldname . ';';
          }
        }
      }
      else {

        // When not saving from widget, save semicolon separated download_fields string
        $fields = $item['download_fields'];
      }
      if ($fields != '') {
        if (!is_array($items)) {
          $items = array();
        }
        $items[$key]['download_fields'] = $fields;
        $items[$key]['download_label'] = $tmp_items[$key]['download_label'];
      }
    }
  }
}