public function RevisionController::view in Workspace 8
Renders an entity revision.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: A RouteMatch object.
Return value
array Array of page elements to render.
Throws
\Exception
File
- src/
Controller/ RevisionController.php, line 37
Class
Namespace
Drupal\workspace\ControllerCode
public function view(RouteMatchInterface $route_match) {
$parameter_name = $route_match
->getRouteObject()
->getOption('_entity_type_id');
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity **/
$entity = $route_match
->getParameter($parameter_name);
if ($entity && $entity instanceof ContentEntityInterface) {
/** @var EntityTypeInterface $entity_type */
$entity_type = $entity
->getEntityType();
return \Drupal::service('entity_type.manager')
->getViewBuilder($entity_type
->id())
->view($entity);
}
else {
throw new \Exception('Invalid entity.');
}
}