You are here

function computed_field_field in Computed Field 6

Same name and namespace in other branches
  1. 5 computed_field.module \computed_field_field()

Implementation of cck hook_field()

File

./computed_field.module, line 231

Code

function computed_field_field($op, &$node, $field, &$node_field, $teaser, $page) {
  switch ($op) {
    case 'load':

      // compute field on load if it isn't stored in the database
      if (!$field['store']) {
        _computed_field_compute_value($node, $field, $node_field);
        return array(
          $field['field_name'] => $node_field,
        );
      }
      break;
    case 'sanitize':

      // compute field for node previews
      if ($node->build_mode == NODE_BUILD_PREVIEW) {
        _computed_field_compute_value($node, $field, $node_field);
      }
      break;
    case 'view':
      $items = array();
      foreach ($node_field as $delta => $item) {
        $items[$delta]['view'] = content_format($field, $item, 'default', $node);
      }
      return theme('field', $node, $field, $items, $teaser, $page);
      break;
    case 'validate':
      break;
    case 'insert':
    case 'update':
      _computed_field_compute_value($node, $field, $node_field);
      break;
  }
}