You are here

public function EntityDebugController::entityRender in Devel 8

Same name and namespace in other branches
  1. 8.3 src/Controller/EntityDebugController.php \Drupal\devel\Controller\EntityDebugController::entityRender()
  2. 8.2 src/Controller/EntityDebugController.php \Drupal\devel\Controller\EntityDebugController::entityRender()
  3. 4.x src/Controller/EntityDebugController.php \Drupal\devel\Controller\EntityDebugController::entityRender()

Returns the render structure of the current entity.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: A RouteMatch object.

Return value

array Array of page elements to render.

File

src/Controller/EntityDebugController.php, line 103

Class

EntityDebugController
Controller for devel entity debug.

Namespace

Drupal\devel\Controller

Code

public function entityRender(RouteMatchInterface $route_match) {
  $output = [];
  $entity = $this
    ->getEntityFromRouteMatch($route_match);
  if ($entity instanceof EntityInterface) {
    $entity_type_id = $entity
      ->getEntityTypeId();
    $view_hook = $entity_type_id . '_view';
    $build = [];

    // If module implements own {entity_type}_view() hook use it, otherwise
    // fallback to the entity view builder if available.
    if (function_exists($view_hook)) {
      $build = $view_hook($entity);
    }
    elseif ($this
      ->entityTypeManager()
      ->hasHandler($entity_type_id, 'view_builder')) {
      $build = $this
        ->entityTypeManager()
        ->getViewBuilder($entity_type_id)
        ->view($entity);
    }
    $output = $this->dumper
      ->exportAsRenderable($build);
  }
  return $output;
}