You are here

function filefield_field in FileField 5.2

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

Implementation of hook_field().

1 call to filefield_field()
filefield_js in ./filefield.module
Menu callback for JavaScript-based uploads.

File

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

Code

function filefield_field($op, &$node, $field, &$items = array()) {
  $fieldname = $field['field_name'];
  switch ($op) {

    // called after content.module loads default data.
    case 'load':
      if (is_array($items)) {
        $items = array_filter($items);

        // drop empty deltas, cuz cck sends 'em some times.
      }
      if (empty($items)) {
        return array();
      }
      foreach ($items as $delta => $item) {
        if (!empty($item['fid'])) {

          // otherwise, merge our info with CCK's, and all is fine.
          $items[$delta] = array_merge($item, _filefield_file_load($item['fid']));
        }
      }
      $items = array_values($items);

      // compact deltas
      return array(
        $fieldname => $items,
      );

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

      // compact deltas
      filefield_clear_field_session($fieldname);
      break;

    // called before content.module defaults.
    case 'update':
      foreach ($items as $delta => $item) {
        $items[$delta] = filefield_file_update($node, $field, $item);
      }
      $items = array_filter($items);

      // unset empty items.
      $items = array_values($items);

      // compact deltas
      filefield_clear_field_session($fieldname);
      break;
    case 'delete revision':
      $db_info = content_database_info($field);
      foreach ($items as $delta => $item) {
        $references = db_result(db_query("SELECT COUNT(vid) FROM {" . $db_info['table'] . "}\n            WHERE nid = %d AND vid != %d\n            AND " . $db_info['columns']['fid']['column'] . " = %d", $node->nid, $node->vid, $item['fid']));
        if ($references || _filefield_file_delete($node, $field, $item)) {
          $items[$delta] = array();
        }
      }
      $items = array_values($items);

      // compact deltas
      break;
    case 'delete':
      foreach ($items as $delta => $item) {
        _filefield_file_delete($node, $field, $item);
      }
      break;
  }
}