You are here

public function MediaViewController::view in Media Expire 8.2

Same name and namespace in other branches
  1. 8 src/Controller/MediaViewController.php \Drupal\media_expire\Controller\MediaViewController::view()

Provides a page to render a single entity.

Parameters

\Drupal\Core\Entity\EntityInterface $_entity: The Entity to be rendered. Note this variable is named $_entity rather than $entity to prevent collisions with other named placeholders in the route.

string $view_mode: (optional) The view mode that should be used to display the entity. Defaults to 'full'.

Return value

array A render array as expected by \Drupal\Core\Render\RendererInterface::render().

Overrides EntityViewController::view

File

src/Controller/MediaViewController.php, line 16

Class

MediaViewController
Extends EntityViewController to overwrite the view method.

Namespace

Drupal\media_expire\Controller

Code

public function view(EntityInterface $media, $view_mode = 'full') {
  $page = $this->entityTypeManager
    ->getViewBuilder($media
    ->getEntityTypeId())
    ->view($media, $view_mode);
  $page['#pre_render'][] = [
    $this,
    'buildTitle',
  ];
  $page['#entity_type'] = $media
    ->getEntityTypeId();
  if (empty($page['#' . $page['#entity_type']])) {
    $page['#' . $page['#entity_type']] = $media;
  }
  if (empty($page['#view_mode'])) {

    // Make sure the view mode is set.
    $page['#view_mode'] = $view_mode;
  }
  return $page;
}