1 field.api.php hook_field_attach_view_alter(&$output, $context)

Perform alterations on field_attach_view() or field_view_field().

This hook is invoked after the field module has performed the operation.

Parameters

$output: The structured content array tree for all of the entity's fields.

$context: An associative array containing:

  • entity_type: The type of $entity; for example, 'node' or 'user'.
  • entity: The entity with fields to render.
  • view_mode: Display mode; for example, 'full' or 'teaser'.
  • display: Either a display mode string or an array of display settings. If this hook is being invoked from field_attach_view(), the 'display' element is set to the display mode string. If this hook is being invoked from field_view_field(), this element is set to the $display argument and the view_mode element is set to '_custom'. See field_view_field() for more information on what its $display argument contains.
  • language: The language code used for rendering.

Related topics

File

core/modules/field/field.api.php, line 1559
Hooks provided by the Field module.

Code

function hook_field_attach_view_alter(&$output, $context) {
  foreach (element_children($output) as $field_name) {
    $element = &$output[$field_name];
    if ($element['#field_type'] == 'taxonomy_term_reference' && $element['#formatter'] == 'taxonomy_term_reference_link') {
      foreach ($element['#items'] as $delta => $item) {
        $term = $item['taxonomy_term'];
        $element[$delta]['#options']['attributes']['title'] = t($term->name);
      }
    }
  }
}