function hook_taxonomy_term_view

Act on a taxonomy term that is being assembled before rendering.

The module may add elements to $term->content prior to rendering. The structure of $term->content is a renderable array as expected by drupal_render().

Parameters

\Drupal\taxonomy\Plugin\Core\Entity\Term $term: The term that is being assembled for rendering.

\Drupal\entity\Plugin\Core\Entity\EntityDisplay $display: The entity_display object holding the display options configured for the term components.

$view_mode: The $view_mode parameter from taxonomy_term_view().

$langcode: The language code used for rendering.

See also

hook_entity_view()

Related topics

File

drupal/core/modules/taxonomy/taxonomy.api.php, line 267
Hooks provided by the Taxonomy module.

Code

function hook_taxonomy_term_view(\Drupal\taxonomy\Plugin\Core\Entity\Term $term, \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display, $view_mode, $langcode) {

  // Only do the extra work if the component is configured to be displayed.
  // This assumes a 'mymodule_addition' extra field has been defined for the
  // vocabulary in hook_field_extra_fields().
  if ($display
    ->getComponent('mymodule_addition')) {
    $term->content['mymodule_addition'] = array(
      '#markup' => mymodule_addition($term),
      '#theme' => 'mymodule_my_additional_field',
    );
  }
}