You are here

public function SupportTicketController::addPage in Support Ticketing System 8

Displays add content links for available support ticket types.

Redirects to support_ticket/add/[type] if only one support ticket type is available.

Return value

array A render array for a list of the support ticket types that can be added; however, if there is only one support ticket type defined for the site, the function redirects to the support ticket add page for that one support ticket type and does not return at all.

See also

support_ticket_menu()

1 string reference to 'SupportTicketController::addPage'
support_ticket.routing.yml in modules/support_ticket/support_ticket.routing.yml
modules/support_ticket/support_ticket.routing.yml

File

modules/support_ticket/src/Controller/SupportTicketController.php, line 75
Contains \Drupal\support_ticket\Controller\SupportTicketController.

Class

SupportTicketController
Returns responses for Support Ticket routes.

Namespace

Drupal\support_ticket\Controller

Code

public function addPage() {
  $build = [
    '#theme' => 'support_ticket_add_list',
    '#cache' => [
      'tags' => $this
        ->entityManager()
        ->getDefinition('support_ticket_type')
        ->getListCacheTags(),
    ],
  ];
  $types = array();

  // Only use support ticket types the user has access to.
  foreach ($this
    ->entityManager()
    ->getStorage('support_ticket_type')
    ->loadMultiple() as $type) {
    $access = $this
      ->entityManager()
      ->getAccessControlHandler('support_ticket')
      ->createAccess($type
      ->id(), NULL, [], TRUE);
    if ($access
      ->isAllowed()) {
      $types[$type
        ->id()] = $type;
    }
    $this->renderer
      ->addCacheableDependency($build, $access);
  }

  // Bypass the support_ticket/add listing if only one support ticket type is available.
  if (count($types) == 1) {
    $type = array_shift($types);
    return $this
      ->redirect('support_ticket.add', array(
      'support_ticket_type' => $type
        ->id(),
    ));
  }
  $build['#content'] = $types;
  return $build;
}