field_attach_preprocess

Versions
7
field_attach_preprocess($obj_type, $object, $element, &$variables)

Populate the template variables with the field values available for rendering.

The $variables array will be populated with all the field instance values associated with the given entity type, keyed by field name; in case of translatable fields the language currently chosen for display will be selected.

Parameters

$obj_type The type of $object; e.g. 'node' or 'user'.

$object The object with fields to render.

$element The structured array containing the values ready for rendering.

$variables The variables array is passed by reference and will be populated with field values.

Related topics

Code

modules/field/field.attach.inc, line 1227

<?php
function field_attach_preprocess($obj_type, $object, $element, &$variables) {
  list(, , $bundle) = entity_extract_ids($obj_type, $object);

  foreach (field_info_instances($obj_type, $bundle) as $instance) {
    $field_name = $instance['field_name'];
    if (isset($element[$field_name]['#language'])) {
      $langcode = $element[$field_name]['#language'];
      $variables[$field_name] = isset($object->{$field_name}[$langcode]) ? $object->{$field_name}[$langcode] : NULL;
    }
  }

  // Let other modules make changes to the $variables array.
  $context = array(
    'obj_type' => $obj_type,
    'object' => $object,
    'element' => $element,
  );
  drupal_alter('field_attach_preprocess', $variables, $context);
}
?>
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.