3 namespace BookStack\Entities;
5 use BookStack\Entities\Models\Book;
6 use BookStack\Entities\Tools\ShelfContext;
7 use Illuminate\View\View;
9 class BreadcrumbsViewComposer
11 protected $entityContextManager;
14 * BreadcrumbsViewComposer constructor.
16 * @param ShelfContext $entityContextManager
18 public function __construct(ShelfContext $entityContextManager)
20 $this->entityContextManager = $entityContextManager;
24 * Modify data when the view is composed.
28 public function compose(View $view)
30 $crumbs = $view->getData()['crumbs'];
31 $firstCrumb = $crumbs[0] ?? null;
32 if ($firstCrumb instanceof Book) {
33 $shelf = $this->entityContextManager->getContextualShelfForBook($firstCrumb);
35 array_unshift($crumbs, $shelf);
36 $view->with('crumbs', $crumbs);