]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/BreadcrumbsViewComposer.php
Fixed failing test after drawio default url change
[bookstack] / app / Entities / BreadcrumbsViewComposer.php
index 97ddbc2dc86764ed930c82d3c549f47b35c83fe1..797162dfb4fb586e8c0b536bb22bd0dea548bd38 100644 (file)
@@ -1,30 +1,36 @@
-<?php namespace BookStack\Entities;
+<?php
 
+namespace BookStack\Entities;
+
+use BookStack\Entities\Models\Book;
+use BookStack\Entities\Tools\ShelfContext;
 use Illuminate\View\View;
 
 class BreadcrumbsViewComposer
 {
-
     protected $entityContextManager;
 
     /**
      * BreadcrumbsViewComposer constructor.
-     * @param EntityContextManager $entityContextManager
+     *
+     * @param ShelfContext $entityContextManager
      */
-    public function __construct(EntityContextManager $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'];
-        if (array_first($crumbs) instanceof Book) {
-            $shelf = $this->entityContextManager->getContextualShelfForBook(array_first($crumbs));
+        $firstCrumb = $crumbs[0] ?? null;
+        if ($firstCrumb instanceof Book) {
+            $shelf = $this->entityContextManager->getContextualShelfForBook($firstCrumb);
             if ($shelf) {
                 array_unshift($crumbs, $shelf);
                 $view->with('crumbs', $crumbs);