PreviewLinkController.php in Preview Link 8
File
src/Controller/PreviewLinkController.php
View source
<?php
namespace Drupal\preview_link\Controller;
use Drupal\Core\Controller\ControllerBase;
class PreviewLinkController extends ControllerBase {
public function preview() {
$entity = $this
->resolveEntity();
return $this
->entityTypeManager()
->getViewBuilder($entity
->getEntityTypeId())
->view($entity);
}
public function title() {
return $this
->resolveEntity()
->label();
}
protected function resolveEntity() {
$route_match = \Drupal::routeMatch();
$preview_link_paramater = $route_match
->getRouteObject()
->getOption('preview_link.entity_type_id');
return $route_match
->getParameter($preview_link_paramater);
}
}