function entity_get_render_display

Returns the entity_display object used to render an entity.

Depending on the configuration of the view mode for the bundle, this can be either the display object associated to the view mode, or the 'default' display.

This function should only be used internally when rendering an entity. When assigning suggested display options for a component in a given view mode, entity_get_display() should be used instead, in order to avoid inadvertently modifying the output of other view modes that might happen to use the 'default' display too. Those options will then be effectively applied only if the view mode is configured to use them.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity being rendered.

string $view_mode: The view mode being rendered.

Return value

\Drupal\entity\Plugin\Core\Entity\EntityDisplay The display object that should be used to render the entity.

See also

entity_get_display().

1 call to entity_get_render_display()

File

drupal/core/includes/entity.inc, line 697
Entity API for handling entities like nodes or users.

Code

function entity_get_render_display(EntityInterface $entity, $view_mode) {
  $entity_type = $entity
    ->entityType();
  $bundle = $entity
    ->bundle();

  // Determine the display to use for rendering this entity. Depending on the
  // configuration of the view mode for this bundle, this will be either the
  // display associated to the view mode, or the 'default' display.
  $view_mode_settings = field_view_mode_settings($entity_type, $bundle);
  $render_view_mode = !empty($view_mode_settings[$view_mode]['status']) ? $view_mode : 'default';
  $display = entity_get_display($entity_type, $bundle, $render_view_mode);
  $display->originalMode = $view_mode;
  return $display;
}