You are here

function template_preprocess_content_field_view in Content Construction Kit (CCK) 6

Process variables for field.tpl.php.

The $variables array contains the following arguments:

  • $node
  • $field
  • $items
  • $teaser
  • $page

See also

field.tpl.php

File

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

Code

function template_preprocess_content_field_view(&$variables) {
  $element = $variables['element'];
  $field = content_fields($element['#field_name'], $element['#node']->type);
  $variables['node'] = $element['#node'];
  $variables['field'] = $field;
  $variables['items'] = array();
  if ($element['#single']) {

    // Single value formatter.
    foreach (element_children($element['items']) as $delta) {
      $variables['items'][$delta] = $element['items'][$delta]['#item'];

      // Use isset() to avoid undefined index message on #children when field values are empty.
      $variables['items'][$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : '';
    }
  }
  else {

    // Multiple values formatter.
    // We display the 'all items' output as $items[0], as if it was the
    // output of a single valued field.
    // Raw values are still exposed for all items.
    foreach (element_children($element['items']) as $delta) {
      $variables['items'][$delta] = $element['items'][$delta]['#item'];
    }
    $variables['items'][0]['view'] = $element['items']['#children'];
  }
  $variables['teaser'] = $element['#teaser'];
  $variables['page'] = $element['#page'];
  $field_empty = TRUE;
  foreach ($variables['items'] as $delta => $item) {
    if (!isset($item['view']) || empty($item['view']) && $item['view'] !== 0) {
      $variables['items'][$delta]['empty'] = TRUE;
    }
    else {
      $field_empty = FALSE;
      $variables['items'][$delta]['empty'] = FALSE;
    }
  }
  $additions = array(
    'field_type' => $field['type'],
    'field_name' => $field['field_name'],
    'field_type_css' => strtr($field['type'], '_', '-'),
    'field_name_css' => strtr($field['field_name'], '_', '-'),
    'label' => $field['widget']['label'],
    'label_display' => isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above',
    'field_empty' => $field_empty,
  );
  $variables = array_merge($variables, $additions);
}