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