You are here

public function SupportTicketViewController::view in Support Ticketing System 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

modules/support_ticket/src/Controller/SupportTicketViewController.php, line 22
Contains \Drupal\support_ticket\Controller\SupportTicketViewController.

Class

SupportTicketViewController
Defines a controller to render a single support ticket.

Namespace

Drupal\support_ticket\Controller

Code

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

    // Set the support ticket path as the canonical URL to prevent duplicate tickets.
    $build['#attached']['html_head_link'][] = array(
      array(
        'rel' => $rel,
        'href' => $support_ticket
          ->url($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' => $support_ticket
            ->url($rel, array(
            'alias' => TRUE,
          )),
        ),
        TRUE,
      );
    }
  }
  return $build;
}