public function record(Request $request, $contenttypeslug, $slug = '')
{
$contenttype = $this->getContentType($contenttypeslug);
// If the contenttype is 'viewless', don't show the record page.
if (isset($contenttype['viewless']) && $contenttype['viewless'] === true) {
$this->abort(Response::HTTP_NOT_FOUND, "Page {$contenttypeslug}/{$slug} not found.");
return null;
}
// Perhaps we don't have a slug. Let's see if we can pick up the 'id', instead.
if (empty($slug)) {
$slug = $request->get('id');
}
$slug = $this->app['slugify']->slugify($slug);
// First, try to get it by slug.
$content = $this->getContent($contenttype['slug'], ['slug' => $slug, 'returnsingle' => true, 'log_not_found' => !is_numeric($slug)]);
if (!$content && is_numeric($slug)) {
// And otherwise try getting it by ID
$content = $this->getContent($contenttype['slug'], ['id' => $slug, 'returnsingle' => true]);
}
// No content, no page!
if (!$content) {
$this->abort(Response::HTTP_NOT_FOUND, "Page {$contenttypeslug}/{$slug} not found.");
return null;
}
// Then, select which template to use, based on our 'cascading templates rules'
$template = $this->templateChooser()->record($content);
// Update the route attributes to change the canonical URL generated.
if ($content->isHome() && $template === $this->getOption('general/homepage_template')) {
$request->attributes->add(['_route' => 'homepage', '_route_params' => []]);
} else {
list($routeName, $routeParams) = $content->getRouteNameAndParams();
if ($routeName) {
$request->attributes->add(['_route' => $routeName, '_route_params' => $routeParams]);
}
}
// Setting the editlink
$this->app['editlink'] = $this->generateUrl('editcontent', ['contenttypeslug' => $contenttype['slug'], 'id' => $content->id]);
$this->app['edittitle'] = $content->getTitle();
// Make sure we can also access it as {{ page.title }} for pages, etc. We set these in the global scope,
// So that they're also available in menu's and templates rendered by extensions.
$globals = ['record' => $content, $contenttype['singular_slug'] => $content];
return $this->render($template, [], $globals);
}