function hook_field_attach_view_alter
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
File
- 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']; } } } } }
© 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.api.php/function/hook_field_attach_view_alter/7.x