function hook_field_attach_view_alter

7.x 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: View mode; for example, 'full' or 'teaser'.
  • display: Either a view 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 view 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

2 functions implement hook_field_attach_view_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

field_test_field_attach_view_alter in drupal/modules/field/tests/field_test.module
Implements hook_field_attach_view_alter().
rdf_field_attach_view_alter in drupal/modules/rdf/rdf.module
Implements hook_field_attach_view_alter().

File

drupal/modules/field/field.api.php, line 1502
Hooks provided by the Field module.

Code

function hook_field_attach_view_alter(&$output, $context) {
  // Append RDF term mappings on displayed taxonomy links.
  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'];
        if (!empty($term->rdf_mapping['rdftype'])) {
          $element[$delta]['#options']['attributes']['typeof'] = $term->rdf_mapping['rdftype'];
        }
        if (!empty($term->rdf_mapping['name']['predicates'])) {
          $element[$delta]['#options']['attributes']['property'] = $term->rdf_mapping['name']['predicates'];
        }
      }
    }
  }
}