1 <?php namespace BookStack\Entities;
3 use BookStack\Entities\Managers\EntityContext;
4 use Illuminate\View\View;
6 class BreadcrumbsViewComposer
9 protected $entityContextManager;
12 * BreadcrumbsViewComposer constructor.
13 * @param EntityContext $entityContextManager
15 public function __construct(EntityContext $entityContextManager)
17 $this->entityContextManager = $entityContextManager;
21 * Modify data when the view is composed.
24 public function compose(View $view)
26 $crumbs = $view->getData()['crumbs'];
27 $firstCrumb = $crumbs[0] ?? null;
28 if ($firstCrumb instanceof Book) {
29 $shelf = $this->entityContextManager->getContextualShelfForBook($firstCrumb);
31 array_unshift($crumbs, $shelf);
32 $view->with('crumbs', $crumbs);