public function BookingController::addPage in Booking and Availability Management Tools for Drupal 8
Displays add content links for available unit type bundles.
Redirects to admin/bat/config/unit_type/add/[type] if only one unit type bundle is available.
Return value
array|\Symfony\Component\HttpFoundation\RedirectResponse A render array for a list of the type bundles that can be added; however, if there is only one type bundle defined for the site, the function will return a RedirectResponse to the type add page for that one type bundle.
1 string reference to 'BookingController::addPage'
- bat_booking.routing.yml in modules/
bat_booking/ bat_booking.routing.yml - modules/bat_booking/bat_booking.routing.yml
File
- modules/
bat_booking/ src/ Controller/ BookingController.php, line 35 - Contains \Drupal\bat_booking\Controller\BookingController.
Class
- BookingController
- Returns responses for Type routes.
Namespace
Drupal\bat_booking\ControllerCode
public function addPage() {
$build = [
'#theme' => 'bat_booking_add_list',
'#cache' => [
'tags' => $this
->entityTypeManager()
->getDefinition('bat_booking_bundle')
->getListCacheTags(),
],
];
$content = [];
// Only use type bundles the user has access to.
foreach ($this
->entityTypeManager()
->getStorage('bat_booking_bundle')
->loadMultiple() as $type) {
$content[$type
->id()] = $type;
}
// Bypass the add listing if only one booking bundle is available.
if (count($content) == 1) {
$type = array_shift($content);
return $this
->redirect('entity.bat_booking.add', [
'booking_bundle' => $type
->id(),
]);
}
$build['#content'] = $content;
return $build;
}