function field_attach_preprocess
field_attach_preprocess($entity_type, $entity, $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
$entity_type: The type of $entity; e.g. 'node' or 'user'.
$entity: The entity 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
File
- modules/field/field.attach.inc, line 1272
- Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.
Code
function field_attach_preprocess($entity_type, $entity, $element, &$variables) { list(, , $bundle) = entity_extract_ids($entity_type, $entity); foreach (field_info_instances($entity_type, $bundle) as $instance) { $field_name = $instance['field_name']; if (isset($element[$field_name]['#language'])) { $langcode = $element[$field_name]['#language']; $variables[$field_name] = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : NULL; } } // Let other modules make changes to the $variables array. $context = array( 'entity_type' => $entity_type, 'entity' => $entity, 'element' => $element, ); drupal_alter('field_attach_preprocess', $variables, $context); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!field!field.attach.inc/function/field_attach_preprocess/7.x