You are here

function _content_field_view in Content Construction Kit (CCK) 5

Format field output based on display settings.

1 call to _content_field_view()
content_view in ./content.module
Generate field render arrays.

File

./content.module, line 597
Allows administrators to associate custom fields to content types.

Code

function _content_field_view(&$node, $teaser = NULL, $page = NULL) {
  $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
  $type = content_types($type_name);
  $field_types = _content_field_types();
  $context = $teaser ? 'teaser' : 'full';
  $return = array();
  if (count($type['fields'])) {
    foreach ($type['fields'] as $field) {
      $node_field = isset($node->{$field}['field_name']) ? $node->{$field}['field_name'] : array();
      $formatter = isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default';
      $value = '';
      if ($formatter != 'hidden') {
        if (content_handle('field', 'view', $field) == CONTENT_CALLBACK_CUSTOM) {
          $module = $field_types[$field['type']]['module'];
          $function = $module . '_field';
          if (function_exists($function)) {
            $value = $function('view', $node, $field, $node_field, $teaser, $page);
          }
        }
        else {
          foreach ($node_field as $delta => $item) {
            $item['#delta'] = $delta;
            $node_field[$delta]['view'] = content_format($field, $item, $formatter, $node);
          }
          $value = theme('field', $node, $field, $node_field, $teaser, $page);
        }
      }
      $return[$field['field_name']] = array(
        '#weight' => $field['widget']['weight'],
        '#value' => $value,
        '#access' => $formatter != 'hidden',
      );

      // test for values in $node_field in case modules added items
      if (isset($node->{$field}['field_name']) || count($node_field)) {
        $node->{$field}['field_name'] = $node_field;
      }
    }
  }
  return $return;
}