2019-04-07 13:28:11 -04:00
|
|
|
<?php namespace BookStack\Entities;
|
|
|
|
|
2019-10-05 07:55:01 -04:00
|
|
|
use BookStack\Entities\Managers\EntityContext;
|
2019-04-07 13:28:11 -04:00
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
class BreadcrumbsViewComposer
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $entityContextManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BreadcrumbsViewComposer constructor.
|
2019-10-05 07:55:01 -04:00
|
|
|
* @param EntityContext $entityContextManager
|
2019-04-07 13:28:11 -04:00
|
|
|
*/
|
2019-10-05 07:55:01 -04:00
|
|
|
public function __construct(EntityContext $entityContextManager)
|
2019-04-07 13:28:11 -04: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-13 18:58:40 -04:00
|
|
|
$firstCrumb = $crumbs[0] ?? null;
|
|
|
|
if ($firstCrumb instanceof Book) {
|
|
|
|
$shelf = $this->entityContextManager->getContextualShelfForBook($firstCrumb);
|
2019-04-07 13:28:11 -04:00
|
|
|
if ($shelf) {
|
|
|
|
array_unshift($crumbs, $shelf);
|
|
|
|
$view->with('crumbs', $crumbs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-05 09:54:37 -04:00
|
|
|
}
|