1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-10-30 07:32:39 +01:00
BookStack/app/Entities/BreadcrumbsViewComposer.php

33 lines
751 B
PHP
Raw Normal View History

2021-06-26 17:23:15 +02:00
<?php
namespace BookStack\Entities;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Tools\ShelfContext;
use Illuminate\View\View;
class BreadcrumbsViewComposer
{
public function __construct(
protected ShelfContext $shelfContext
) {
}
/**
* Modify data when the view is composed.
*/
public function compose(View $view): void
{
$crumbs = $view->getData()['crumbs'];
2019-09-14 00:58:40 +02:00
$firstCrumb = $crumbs[0] ?? null;
2019-09-14 00:58:40 +02:00
if ($firstCrumb instanceof Book) {
$shelf = $this->shelfContext->getContextualShelfForBook($firstCrumb);
if ($shelf) {
array_unshift($crumbs, $shelf);
$view->with('crumbs', $crumbs);
}
}
}
2019-05-05 15:54:37 +02:00
}