You are here

public function EventSeriesController::addPage in Booking and Availability Management Tools for Drupal 8

Displays add event links for available event series types.

Redirects to admin/bat/events/event_series/add[type] if only one event series type is available.

Return value

array|\Symfony\Component\HttpFoundation\RedirectResponse A render array for a list of the event series types that can be added; however, if there is only one event series type defined for the site, the function will return a RedirectResponse to the event add page for that one event type.

1 string reference to 'EventSeriesController::addPage'
bat_event_series.routing.yml in modules/bat_event_series/bat_event_series.routing.yml
modules/bat_event_series/bat_event_series.routing.yml

File

modules/bat_event_series/src/Controller/EventSeriesController.php, line 38
Contains \Drupal\bat_event_series\Controller\EventSeriesController.

Class

EventSeriesController
Returns responses for Type routes.

Namespace

Drupal\bat_event_series\Controller

Code

public function addPage() {
  $build = [
    '#theme' => 'bat_event_series_add_list',
    '#cache' => [
      'tags' => $this
        ->entityTypeManager()
        ->getDefinition('bat_event_series_type')
        ->getListCacheTags(),
    ],
  ];
  $content = [];

  // Only use event series types the user has access to.
  foreach ($this
    ->entityTypeManager()
    ->getStorage('bat_event_series_type')
    ->loadMultiple() as $type) {
    $access = $this
      ->entityTypeManager()
      ->getAccessControlHandler('bat_event_series')
      ->createAccess($type
      ->id(), NULL, [], TRUE);
    if ($access
      ->isAllowed()) {
      $content[$type
        ->id()] = $type;
    }
  }

  // Bypass the add listing if only one event series type is available.
  if (count($content) == 1) {
    $type = array_shift($content);
    return $this
      ->redirect('entity.bat_event_series.add_form', [
      'event_series_type' => $type
        ->id(),
    ]);
  }
  $build['#content'] = $content;
  return $build;
}