public function LogController::addPage in Log entity 8
Displays add content links for available content types.
Redirects to log/add/[type] if only one content type is available.
Return value
array|\Symfony\Component\HttpFoundation\RedirectResponse A render array for a list of the log types that can be added; however, if there is only one log type defined for the site, the function will return a RedirectResponse to the log add page for that one log type.
1 string reference to 'LogController::addPage'
File
- src/
Controller/ LogController.php, line 74 - Contains \Drupal\log\Controller\LogController.
Class
- LogController
- Returns responses for Log routes.
Namespace
Drupal\log\ControllerCode
public function addPage() {
$build = [
'#theme' => 'log_add_list',
'#cache' => [
'tags' => $this
->entityManager()
->getDefinition('log_type')
->getListCacheTags(),
],
];
$content = array();
// Only use log types the user has access to.
foreach ($this
->entityManager()
->getStorage('log_type')
->loadMultiple() as $type) {
$access = $this
->entityManager()
->getAccessControlHandler('log')
->createAccess($type
->id(), NULL, [], TRUE);
if ($access
->isAllowed()) {
$content[$type
->id()] = $type;
}
$this->renderer
->addCacheableDependency($build, $access);
}
// Bypass the log/add listing if only one content type is available.
if (count($content) == 1) {
$type = array_shift($content);
return $this
->redirect('log.add', array(
'log_type' => $type
->id(),
));
}
$build['#content'] = $content;
return $build;
}