- $book = $this->entityRepo->getBySlug('book', $bookSlug);
- $chapter = $chapterSlug ? $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug) : null;
+ if ($chapterSlug !== null) {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $book = $chapter->book;
+ } else {
+ $chapter = null;
+ $book = $this->entityRepo->getBySlug('book', $bookSlug);
+ }
+