You are here

function filefield_field_load in FileField 6.3

Implementation of CCK's hook_field($op = 'load').

File

./filefield_field.inc, line 127
FileField CCK field hooks and callbacks.

Code

function filefield_field_load($node, $field, &$items, $teaser, $page) {
  if (empty($items)) {
    return array();
  }
  foreach ($items as $delta => $item) {

    // Despite hook_content_is_empty(), CCK still doesn't filter out
    // empty items from $op = 'load', so we need to do that ourselves.
    if (empty($item['fid']) || !($file = field_file_load($item['fid']))) {
      $items[$delta] = NULL;
    }
    else {
      if (isset($item['data']) && !empty($item['data'])) {
        $item['data'] = unserialize($item['data']);
      }

      // Temporary fix to unserialize data serialized multiple times.
      // See the FileField issue http://drupal.org/node/402860.
      // And the CCK issue http://drupal.org/node/407446.
      while (!empty($item['data']) && is_string($item['data'])) {
        $item['data'] = unserialize($item['data']);
      }

      // Merge any data added by modules in hook_file_load().
      if (isset($file['data']) && isset($item['data'])) {
        $file['data'] = array_merge((array) $file['data'], (array) $item['data']);
      }
      $items[$delta] = array_merge($file, $item);
    }
  }
  return array(
    $field['field_name'] => $items,
  );
}