You are here

public function RegistrationController::RegistrationAddPage in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Controller/RegistrationController.php \Drupal\rng\Controller\RegistrationController::registrationAddPage()
  2. 3.x src/Controller/RegistrationController.php \Drupal\rng\Controller\RegistrationController::registrationAddPage()

Generates a list of registration types for an event.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The matched route.

string $event: The parameter to find the event entity.

Return value

array A registration form.

File

src/Controller/RegistrationController.php, line 56

Class

RegistrationController
Controller for registration entities.

Namespace

Drupal\rng\Controller

Code

public function RegistrationAddPage(RouteMatchInterface $route_match, $event) {
  $event_entity = $route_match
    ->getParameter($event);
  $render = [];
  $registration_types = $this->eventManager
    ->getMeta($event_entity)
    ->getRegistrationTypes();
  if (count($registration_types) == 1) {
    $registration_type = array_shift($registration_types);
    return $this
      ->redirect('rng.event.' . $event . '.register', [
      $event => $event_entity
        ->id(),
      'registration_type' => $registration_type
        ->id(),
    ]);
  }
  else {
    $label = \Drupal::entityTypeManager()
      ->getDefinition('registration_type')
      ->getLabel();
    $render['links'] = array(
      '#title' => $this
        ->t('Select @entity_type', [
        '@entity_type' => $label,
      ]),
      '#theme' => 'item_list',
      '#items' => [],
    );
  }
  foreach ($registration_types as $registration_type) {
    $item = [];
    $url = new Url('rng.event.' . $event . '.register', [
      $event => $event_entity
        ->id(),
      'registration_type' => $registration_type
        ->id(),
    ]);
    $item[] = [
      '#type' => 'link',
      '#title' => $registration_type
        ->label(),
      '#url' => $url,
      '#prefix' => '<h3>',
      '#suffix' => '</h3>',
    ];
    if (!empty($registration_type->description)) {
      $item[] = [
        '#markup' => $registration_type->description,
      ];
    }
    $render['links']['#items'][] = $item;
  }
  return $render;
}