Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

All hooks involved in displaying an entity now receive the EntityViewDisplay object used for rendering the entity as a parameter.

This object encloses the configured options to be used for each of the displayed entity components, avoiding the need for hook implementations themselves to pull those options from wherever they might be stored.

Related change record:
Introduced EntityViewDisplay config entities for more information about how EntityViewDisplay objects are defined and altered.

API changes:

Entity rendering:
The following hooks all receive an EntityViewDisplay object as an additional parameter ::
- hook_comment_view()
- hook_comment_view_alter()
- hook_view()
- hook_node_view()
- hook_node_view_alter()
- hook_taxonomy_term_view()
- hook_taxonomy_term_view_alter()
- hook_user_view()
- hook_user_view_alter()
- hook_entity_view()
- hook_entity_view_alter()
- hook_entity_prepare_view() (this hook runs on an array of entities, and thus receives an array of EntityDisplay objects, keyed by entity bundle name).

Additionally, the field_extra_fields_get_display() function has been removed. This function was typically used to retrieve the display options configured for the "extra fields" of an entity, and is now not needed anymore.

Code example:


Drupal 7:

function hook_node_view($node, $view_mode, $langcode) {
  $display = field_extra_fields_get_display('node', $node->type, $view_mode);
  if (!empty($display['mymodule_extra_field'])) {
    $node->content['mymodule_addition'] = array(
      '#markup' => mymodule_addition($node),
      '#theme' => 'mymodule_my_additional_field',
    );
  }
}

Drupal 8:

function hook_node_view(Node $node, EntityViewDisplayInterface $display, $view_mode, $langcode) {
  if ($display->getComponent('mymodule_addition')) {
    $node->content['mymodule_addition'] = array(
      '#markup' => mymodule_addition($node),
      '#theme' => 'mymodule_my_additional_field',
    );
  }
}
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done