You are here

function filefield_field in FileField 5

Same name and namespace in other branches
  1. 5.2 filefield.module \filefield_field()
  2. 6.3 filefield.module \filefield_field()
  3. 6.2 filefield.module \filefield_field()

Implementation of hook_field().

File

./filefield.module, line 139
Defines a file field type.

Code

function filefield_field($op, $node, $field, &$node_field, $teaser, $page) {
  $fieldname = $field['field_name'];
  switch ($op) {
    case 'load':
      $output = array();
      if (count($node_field)) {
        $values = array();
        foreach ($node_field as $delta => $file) {
          if (!empty($file)) {
            $node_field[$delta] = array_merge($node_field[$delta], _filefield_file_load($file['fid']));
          }
          $output = array(
            $fieldname => $node_field,
          );
        }
      }
      break;
    case 'view':

      // left for compatability with versions of content.module before
      // the display settings patch. this is deprecated.
      $formatter = 'default';
      foreach ($node_field as $delta => $item) {
        if (!$item['remove'] && $item['list']) {
          $node_field[$delta]['view'] = content_format($field, $item, $page ? 'default' : 'preview');
        }
      }
      $output = theme('field', $node, $field, $node_field, $teaser, $page);
      break;

    // called before content.module defaults.
    case 'insert':
      foreach ($node_field as $delta => $item) {
        $node_field[$delta] = filefield_file_insert($node, $item, $field);
      }
      break;

    // called before content.module defaults.
    case 'update':
      foreach ($node_field as $delta => $item) {
        $node_field[$delta] = filefield_file_update($node, $item, $field);
      }
      break;
    case 'delete':
      foreach ($node_field as $delta => $item) {
        _filefield_file_delete($item, $field['field_name']);
      }
      break;
  }
  return $output;
}