]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/BreadcrumbsViewComposer.php
Improve sorting Shelf Books
[bookstack] / app / Entities / BreadcrumbsViewComposer.php
index 7745d9aee5418549143237a550a78f0599eb8224..cf7cf296c94fdbd8cdcb3b7dffd59767cb8000ad 100644 (file)
@@ -1,5 +1,7 @@
 <?php namespace BookStack\Entities;
 
+use BookStack\Entities\Models\Book;
+use BookStack\Entities\Tools\ShelfContext;
 use Illuminate\View\View;
 
 class BreadcrumbsViewComposer
@@ -9,9 +11,9 @@ class BreadcrumbsViewComposer
 
     /**
      * BreadcrumbsViewComposer constructor.
-     * @param EntityContextManager $entityContextManager
+     * @param ShelfContext $entityContextManager
      */
-    public function __construct(EntityContextManager $entityContextManager)
+    public function __construct(ShelfContext $entityContextManager)
     {
         $this->entityContextManager = $entityContextManager;
     }
@@ -23,12 +25,13 @@ class BreadcrumbsViewComposer
     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);
             }
         }
     }
-}
\ No newline at end of file
+}