function hook_field_attach_view_alter

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: The entity with fields to render.
  • view_mode: View mode; for example, 'full' or 'teaser'.
  • display_options: Either a view mode string or an array of display options. If this hook is being invoked from field_attach_view(), the 'display_options' 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_options argument and the view_mode element is set to '_custom'. See field_view_field() for more information on what its $display_options argument contains.
  • langcode: 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/core/modules/field/tests/modules/field_test/field_test.module
Implements hook_field_attach_view_alter().
rdf_field_attach_view_alter in drupal/core/modules/rdf/rdf.module
Implements hook_field_attach_view_alter().

File

drupal/core/modules/field/field.api.php, line 1057

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'] == 'entity_reference' && $element['#formatter'] == 'entity_reference_label') {
      foreach ($element['#items'] as $delta => $item) {
        $term = $item['entity'];
        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'];
        }
      }
    }
  }
}