2019-04-07 19:28:11 +02:00
|
|
|
<?php namespace BookStack\Entities;
|
|
|
|
|
2020-11-22 01:17:45 +01:00
|
|
|
use BookStack\Entities\Models\Book;
|
2020-11-22 00:20:54 +01:00
|
|
|
use BookStack\Entities\Tools\ShelfContext;
|
2019-04-07 19:28:11 +02:00
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
class BreadcrumbsViewComposer
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $entityContextManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BreadcrumbsViewComposer constructor.
|
2020-11-22 00:20:54 +01:00
|
|
|
* @param ShelfContext $entityContextManager
|
2019-04-07 19:28:11 +02:00
|
|
|
*/
|
2020-11-22 00:20:54 +01:00
|
|
|
public function __construct(ShelfContext $entityContextManager)
|
2019-04-07 19:28:11 +02:00
|
|
|
{
|
|
|
|
$this->entityContextManager = $entityContextManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify data when the view is composed.
|
|
|
|
* @param View $view
|
|
|
|
*/
|
|
|
|
public function compose(View $view)
|
|
|
|
{
|
|
|
|
$crumbs = $view->getData()['crumbs'];
|
2019-09-14 00:58:40 +02:00
|
|
|
$firstCrumb = $crumbs[0] ?? null;
|
|
|
|
if ($firstCrumb instanceof Book) {
|
|
|
|
$shelf = $this->entityContextManager->getContextualShelfForBook($firstCrumb);
|
2019-04-07 19:28:11 +02:00
|
|
|
if ($shelf) {
|
|
|
|
array_unshift($crumbs, $shelf);
|
|
|
|
$view->with('crumbs', $crumbs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-05 15:54:37 +02:00
|
|
|
}
|