You are here

public function LogViewController::view in Log entity 8

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/LogViewController.php, line 21
Contains \Drupal\log\Controller\LogViewController.

Class

LogViewController
Defines a controller to render a single log.

Namespace

Drupal\log\Controller

Code

public function view(EntityInterface $log, $view_mode = 'full') {
  $build = parent::view($log, $view_mode);
  foreach ($log
    ->uriRelationships() as $rel) {

    // Set the log path as the canonical URL to prevent duplicate content.
    $build['#attached']['html_head_link'][] = array(
      array(
        'rel' => $rel,
        'href' => $log
          ->toUrl($rel),
      ),
      TRUE,
    );
    if ($rel == 'canonical') {

      // Set the non-aliased canonical path as a default shortlink.
      $build['#attached']['html_head_link'][] = array(
        array(
          'rel' => 'shortlink',
          'href' => $log
            ->toUrl($rel, array(
            'alias' => TRUE,
          )),
        ),
        TRUE,
      );
    }
  }
  return $build;
}