1 taxonomy.module taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NULL)

Builds a structured array representing the term's content.

The content built for the taxonomy term (field values, file attachments or other term components) will vary depending on the $view_mode parameter.

Backdrop core defines the following display modes for terms, with the following default use cases:

  • full (default): term is displayed on its own page (taxonomy/term/123)

Contributed modules might define additional display modes, or use existing display modes in additional contexts.


$term: A taxonomy term object.

$view_mode: (optional) Display mode, e.g. 'full' or 'teaser'. Defaults to 'full'.

$langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.


core/modules/taxonomy/taxonomy.module, line 710
Enables the organization of content into categories.


function taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NULL) {
  if (!isset($langcode)) {
    $langcode = $GLOBALS['language_content']->language;

  // Remove previously built content, if exists.
  $term->content = array();

  // Allow modules to change the display mode.
  $view_mode = key(entity_view_mode_prepare('taxonomy_term', array($term->tid => $term), $view_mode, $langcode));

  // Add the term description if the term has one and it is visible.
  $type = 'taxonomy_term';
  $entity_ids = entity_extract_ids($type, $term);
  $settings = field_view_mode_settings($type, $entity_ids[2]);
  $fields = field_extra_fields_get_display($type, $entity_ids[2], $view_mode);
  if (!empty($term->description) && isset($fields['description']) && $fields['description']['visible']) {
    $term->content['description'] = array(
      '#markup' => check_markup($term->description, $term->format, '', TRUE),
      '#weight' => $fields['description']['weight'],
      '#prefix' => '<div class="taxonomy-term-description">',
      '#suffix' => '</div>',

  // Build fields content.
  // In case of a multiple view, taxonomy_term_view_multiple() already ran the
  // 'prepare_view' step. An internal flag prevents the operation from running
  // twice.
  field_attach_prepare_view('taxonomy_term', array($term->tid => $term), $view_mode, $langcode);
  entity_prepare_view('taxonomy_term', array($term->tid => $term), $langcode);
  $term->content += field_attach_view('taxonomy_term', $term, $view_mode, $langcode);

  // Allow modules to make their own additions to the taxonomy term.
  module_invoke_all('taxonomy_term_view', $term, $view_mode, $langcode);
  module_invoke_all('entity_view', $term, 'taxonomy_term', $view_mode, $langcode);

  // Make sure the current display mode is stored if no module has already
  // populated the related key.
  $term->content += array('#view_mode' => $view_mode);