1 <?php namespace BookStack\Entities;
3 use BookStack\Entities\Models\Book;
4 use BookStack\Entities\Tools\ShelfContext;
5 use Illuminate\View\View;
7 class BreadcrumbsViewComposer
10 protected $entityContextManager;
13 * BreadcrumbsViewComposer constructor.
14 * @param ShelfContext $entityContextManager
16 public function __construct(ShelfContext $entityContextManager)
18 $this->entityContextManager = $entityContextManager;
22 * Modify data when the view is composed.
25 public function compose(View $view)
27 $crumbs = $view->getData()['crumbs'];
28 $firstCrumb = $crumbs[0] ?? null;
29 if ($firstCrumb instanceof Book) {
30 $shelf = $this->entityContextManager->getContextualShelfForBook($firstCrumb);
32 array_unshift($crumbs, $shelf);
33 $view->with('crumbs', $crumbs);