]> BookStack Code Mirror - bookstack/blob - app/Entities/BreadcrumbsViewComposer.php
Added crude example of captcha usage
[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         if (array_first($crumbs) instanceof Book) {
27             $shelf = $this->entityContextManager->getContextualShelfForBook(array_first($crumbs));
28             if ($shelf) {
29                 array_unshift($crumbs, $shelf);
30                 $view->with('crumbs', $crumbs);
31             }
32         }
33     }
34 }