+ // Page in chapter
+ if ($entity->isA('page') && $entity->chapter) {
+ $entities = $this->entityRepo->getChapterChildren($entity->chapter);
+ }
+
+ // Page in book or chapter
+ if (($entity->isA('page') && !$entity->chapter) || $entity->isA('chapter')) {
+ $entities = $this->entityRepo->getBookDirectChildren($entity->book);
+ }
+
+ // Book
+ // Gets just the books in a shelf if shelf is in context
+ if ($entity->isA('book')) {
+ $contextShelf = $this->entityContextManager->getContextualShelfForBook($entity);
+ if ($contextShelf) {
+ $entities = $this->entityRepo->getBookshelfChildren($contextShelf);
+ } else {
+ $entities = $this->entityRepo->getAll('book');
+ }
+ }