2021-06-26 11:23:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Entities;
|
2019-04-07 13:28:11 -04:00
|
|
|
|
2020-11-21 19:17:45 -05:00
|
|
|
use BookStack\Entities\Models\Book;
|
2020-11-21 18:20:54 -05:00
|
|
|
use BookStack\Entities\Tools\ShelfContext;
|
2019-04-07 13:28:11 -04:00
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
class BreadcrumbsViewComposer
|
|
|
|
{
|
2023-09-16 13:25:08 -04:00
|
|
|
public function __construct(
|
|
|
|
protected ShelfContext $shelfContext
|
|
|
|
) {
|
2019-04-07 13:28:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify data when the view is composed.
|
|
|
|
*/
|
2023-09-16 13:25:08 -04:00
|
|
|
public function compose(View $view): void
|
2019-04-07 13:28:11 -04:00
|
|
|
{
|
|
|
|
$crumbs = $view->getData()['crumbs'];
|
2019-09-13 18:58:40 -04:00
|
|
|
$firstCrumb = $crumbs[0] ?? null;
|
2023-09-16 13:25:08 -04:00
|
|
|
|
2019-09-13 18:58:40 -04:00
|
|
|
if ($firstCrumb instanceof Book) {
|
2023-09-16 13:25:08 -04:00
|
|
|
$shelf = $this->shelfContext->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
|
|
|
}
|