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