Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better check for isSpecialPage if homepage: is set to a contenttype (listing) #1451

Merged
merged 2 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Controller/Frontend/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public function homepage(ContentRepository $contentRepository): Response
$params = explode('/', $homepage);
$contentType = $this->config->get('contenttypes/' . $params[0]);

if (! $contentType) {
$message = sprintf('Homepage is set to `%s`, but that ContentType is not defined', $homepage);

throw new \Exception($message);
}

// Perhaps we need a listing instead. If so, forward the Request there
if (! $contentType->get('singleton') && ! isset($params[1])) {
return $this->forward('Bolt\Controller\Frontend\ListingController::listing', [
Expand Down
6 changes: 4 additions & 2 deletions src/Twig/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,11 @@ private function isSpecialpage(Content $content, string $type): bool
continue;
}

$idOrSlug = $item[1] ?? null;

// Success if we either have no id/slug for a Singleton, or if the id/slug matches
if ((empty($item[1]) && $content->getDefinition()->get('singleton')) ||
($item[1] === $content->getSlug() || $item[1] === (string) $content->getId())) {
if ((empty($idOrSlug) && $content->getDefinition()->get('singleton')) ||
($idOrSlug === $content->getSlug() || $idOrSlug === (string) $content->getId())) {
return true;
}
}
Expand Down