function template_preprocess_content_field in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 6.3 content.module \template_preprocess_content_field()
Theme preprocess function for field.tpl.php.
The $variables array contains the following arguments:
- $node
- $field
- $items
- $teaser
- $page
TODO : this should live in theme/theme.inc, but then the preprocessor doesn't get called when the theme overrides the template. Bug in theme layer ?
See also
File
- ./
content.module, line 2362 - Allows administrators to associate custom fields to content types.
Code
function template_preprocess_content_field(&$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']) && (string) $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' => check_plain(t($field['widget']['label'])),
'label_display' => $element['#label_display'],
'field_empty' => $field_empty,
'template_files' => array(
'content-field',
'content-field-' . $element['#field_name'],
'content-field-' . $element['#node']->type,
'content-field-' . $element['#field_name'] . '-' . $element['#node']->type,
),
);
$variables = array_merge($variables, $additions);
}