The processes for building and processing the display modes of all entity types is now available as methods directly on the entities and can by called through a single entity_view() function if needed.

For example the following separate functions used to need to be called depending on the type of entity:
 

  • node_view()
  • comment_view()
  • file_view()
  • user_view()
  • taxonomy_term_view()

While these all can still be used, if the type of entity is unknown or needs to be handled the same regardless of it's type, the following are also now available:
 

  • $node->view()
  • $comment->view()
  • $file->view()
  • $user->view()
  • $taxonomy_term->view()

Or generally, this can be applied to all entities using either of the following:
 

  • $entity->view()
  • entity_view($entity)

Additionally, there was often a "*_build_content" function for each entity type, such as node_build_content() and file_build_content(). These functions have also been made available as methods generally on entities, so either of the following can be used:
 

  • $entity->buildContent()
  • entity_build_content($entity);

Changes made adding these new methods and wrappers should be backwards-compatible, but modules that previously had been working-around limitations may want to simplify their code.

Before Backdrop 1.21.0:

// Assuming a view_*() function exists:
$view_function = 'view_' . $entity->entityType()
$output = $view_function($entity);

// Or manually checking each type:
switch ($entity->entityType()) {
  case 'node':
    $output = node_view($entity);
  case 'comment':
    $output = comment_view($entity);
  case 'file':
    $output = file_view($entity);
  case 'taxonomy_term':
    $output = taxonomy_term_view($entity);
  case 'user':
    $output = user_view($entity);
  default:
    $output = NULL;
}

Backdrop 1.21.0 and newer:

// Simply use the new method directly on the object.
$output = $entity->view();

// Or the generic entity_view() function.
$output = entity_view($entity);

 

Introduced in branch: 
1.x
Introduced in version: 
1.21.0
Impacts: 
Module developers