]> BookStack Code Mirror - bookstack/blob - app/Entities/BreadcrumbsViewComposer.php
added additional color settings into UI
[bookstack] / app / Entities / BreadcrumbsViewComposer.php
1 <?php namespace BookStack\Entities;
2
3 use BookStack\Entities\Managers\EntityContext;
4 use Illuminate\View\View;
5
6 class BreadcrumbsViewComposer
7 {
8
9     protected $entityContextManager;
10
11     /**
12      * BreadcrumbsViewComposer constructor.
13      * @param EntityContext $entityContextManager
14      */
15     public function __construct(EntityContext $entityContextManager)
16     {
17         $this->entityContextManager = $entityContextManager;
18     }
19
20     /**
21      * Modify data when the view is composed.
22      * @param View $view
23      */
24     public function compose(View $view)
25     {
26         $crumbs = $view->getData()['crumbs'];
27         $firstCrumb = $crumbs[0] ?? null;
28         if ($firstCrumb instanceof Book) {
29             $shelf = $this->entityContextManager->getContextualShelfForBook($firstCrumb);
30             if ($shelf) {
31                 array_unshift($crumbs, $shelf);
32                 $view->with('crumbs', $crumbs);
33             }
34         }
35     }
36 }