mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 12:16:07 +00:00
![Dan Brown](/assets/img/avatar_default.png)
Tools seems to fit better since the classes were a bit of a mixed bunch and did not always manage. Also simplified the structure of the SlugGenerator class. Also focused EntityContext on shelves and simplified to use session helper.
37 lines
937 B
PHP
37 lines
937 B
PHP
<?php namespace BookStack\Entities;
|
|
|
|
use BookStack\Entities\Tools\ShelfContext;
|
|
use Illuminate\View\View;
|
|
|
|
class BreadcrumbsViewComposer
|
|
{
|
|
|
|
protected $entityContextManager;
|
|
|
|
/**
|
|
* BreadcrumbsViewComposer constructor.
|
|
* @param ShelfContext $entityContextManager
|
|
*/
|
|
public function __construct(ShelfContext $entityContextManager)
|
|
{
|
|
$this->entityContextManager = $entityContextManager;
|
|
}
|
|
|
|
/**
|
|
* Modify data when the view is composed.
|
|
* @param View $view
|
|
*/
|
|
public function compose(View $view)
|
|
{
|
|
$crumbs = $view->getData()['crumbs'];
|
|
$firstCrumb = $crumbs[0] ?? null;
|
|
if ($firstCrumb instanceof Book) {
|
|
$shelf = $this->entityContextManager->getContextualShelfForBook($firstCrumb);
|
|
if ($shelf) {
|
|
array_unshift($crumbs, $shelf);
|
|
$view->with('crumbs', $crumbs);
|
|
}
|
|
}
|
|
}
|
|
}
|