function EntityDebugController::entityRender
Same name in other branches
- 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 125
Class
- EntityDebugController
- Controller for devel entity debug.
Namespace
Drupal\devel\ControllerCode
public function entityRender(RouteMatchInterface $route_match) : array {
$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;
}