/**
  * Checks access to the support_ticket preview page.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param \Drupal\support_ticket\SupportTicketInterface $support_ticket_preview
  *   The support_ticket that is being previewed.
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(AccountInterface $account, SupportTicketInterface $support_ticket_preview)
 {
     if ($support_ticket_preview->isNew()) {
         $access_controller = $this->entityManager->getAccessControlHandler('support_ticket');
         return $access_controller->createAccess($support_ticket_preview->bundle(), $account, [], TRUE);
     } else {
         return $support_ticket_preview->access('update', $account, TRUE);
     }
 }
 /**
  * Generates an overview table of older revisions of a support ticket.
  *
  * @param \Drupal\support_ticket\SupportTicketInterface $support_ticket
  *   A support_ticket object.
  *
  * @return array
  *   An array as expected by drupal_render().
  */
 public function revisionOverview(SupportTicketInterface $support_ticket)
 {
     $account = $this->currentUser();
     $support_ticket_storage = $this->entityManager()->getStorage('support_ticket');
     $type = $support_ticket->getType();
     $build = array();
     $build['#title'] = $this->t('Revisions for %title', array('%title' => $support_ticket->label()));
     $header = array($this->t('Revision'), $this->t('Operations'));
     $revert_permission = ($account->hasPermission("revert {$type} revisions") || $account->hasPermission('revert all revisions') || $account->hasPermission('administer support tickets')) && $support_ticket->access('update');
     $delete_permission = ($account->hasPermission("delete {$type} revisions") || $account->hasPermission('delete all revisions') || $account->hasPermission('administer support tickets')) && $support_ticket->access('delete');
     $rows = array();
     $vids = $support_ticket_storage->revisionIds($support_ticket);
     foreach (array_reverse($vids) as $vid) {
         $revision = $support_ticket_storage->loadRevision($vid);
         $username = ['#theme' => 'username', '#account' => $revision->uid->entity];
         // Use revision link to link to revisions that are not active.
         $date = $this->dateFormatter->format($revision->revision_timestamp->value, 'short');
         if ($vid != $support_ticket->getRevisionId()) {
             $link = $this->l($date, new Url('entity.support_ticket.revision', ['support_ticket' => $support_ticket->id(), 'support_ticket_revision' => $vid]));
         } else {
             $link = $support_ticket->link($date);
         }
         $row = [];
         $column = ['data' => ['#type' => 'inline_template', '#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}', '#context' => ['date' => $link, 'username' => $this->renderer->renderPlain($username), 'message' => ['#markup' => $revision->revision_log->value]]]];
         // @todo Simplify once https://www.drupal.org/node/2334319 lands.
         $this->renderer->addCacheableDependency($column['data'], $username);
         $row[] = $column;
         if ($vid == $support_ticket->getRevisionId()) {
             $row[0]['class'] = ['revision-current'];
             $row[] = ['data' => ['#prefix' => '<em>', '#markup' => $this->t('current revision'), '#suffix' => '</em>'], 'class' => ['revision-current']];
         } else {
             $links = [];
             if ($revert_permission) {
                 $links['revert'] = ['title' => $this->t('Revert'), 'url' => Url::fromRoute('support_ticket.revision_revert_confirm', ['support_ticket' => $support_ticket->id(), 'support_ticket_revision' => $vid])];
             }
             if ($delete_permission) {
                 $links['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('support_ticket.revision_delete_confirm', ['support_ticket' => $support_ticket->id(), 'support_ticket_revision' => $vid])];
             }
             $row[] = ['data' => ['#type' => 'operations', '#links' => $links]];
         }
         $rows[] = $row;
     }
     $build['support_ticket_revisions_table'] = array('#theme' => 'table', '#rows' => $rows, '#header' => $header, '#attached' => array('library' => array('support_ticket/drupal.support_ticket.admin')));
     return $build;
 }