template_preprocess_field

Versions
7
template_preprocess_field(&$variables)

Theme preprocess function for field.tpl.php.

See also

field.tpl.php

Related topics

Code

modules/field/field.module, line 684

<?php
function template_preprocess_field(&$variables) {
  $element = $variables['element'];
  $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
  $field = field_info_field($element['#field_name']);

  // @todo Convert to using drupal_html_class() after benchmarking the impact of
  //   doing so.
  $field_type_css = strtr($field['type'], '_', '-');
  $field_name_css = strtr($field['field_name'], '_', '-');

  // Prepare an $items variable that the template can simply loop on.
  // Filter out non-children properties that might have been added if the
  // renderable array has gone through form_builder().
  $items = array_intersect_key($element, array_flip(element_children($element)));

  $additions = array(
    'object' => $element['#object'],
    'field' => $field,
    'instance' => $instance,
    'build_mode' => $element['#build_mode'],
    'items' => $items,
    'field_type' => $field['type'],
    'field_name' => $field['field_name'],
    'field_type_css' => $field_type_css,
    'field_name_css' => $field_name_css,
    'label' => check_plain($element['#title']),
    'label_display' => $element['#label_display'],
    'label_hidden' => $element['#label_display'] == 'hidden',
    'field_language' => $element['#language'],
    'field_translatable' => $field['translatable'],
    'classes_array' => array(
      'field-name-' . $field_name_css,
      'field-type-' . $field_type_css,
      'field-label-' . $element['#label_display'],
    ),
    'template_files' => array(
      'field',
      'field-' . $element['#field_name'],
      'field-' . $element['#bundle'],
      'field-' . $element['#field_name'] . '-' . $element['#bundle'],
    ),
  );
  $variables = array_merge($variables, $additions);

  // Initialize attributes for each item.
  foreach ($variables['items'] as $delta => $item) {
    $variables['item_attributes_array'][$delta] = array();
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.