]> BookStack Code Mirror - bookstack/commitdiff
Fix Book form (create) returning to the full books list on cancel 1687/head
authorChristopher Wilkinson <redacted>
Thu, 26 Sep 2019 21:51:24 +0000 (22:51 +0100)
committerChristopher Wilkinson <redacted>
Thu, 26 Sep 2019 21:51:24 +0000 (22:51 +0100)
Fixes #1662
Added a small block of logic to determine the correct URL to attribute to the cancel button on a given page create form.
If adding a book from a bookshelf, return to the bookshelf. If editing a book, return to the book. In all other cases, return to the full books list.

resources/views/books/form.blade.php
tests/Entity/EntityTest.php

index 8960b41359584ceb2cdec3b41039a90f0b1bfdde..91a3899de34f9d06e21015d840c85540e195046b 100644 (file)
 </div>
 
 <div class="form-group text-right">
 </div>
 
 <div class="form-group text-right">
-    <a href="{{ isset($book) ? $book->getUrl() : url('/books') }}" class="button outline">{{ trans('common.cancel') }}</a>
+    <?php
+        if (isset($bookshelf)) {
+            $cancelUrl = $bookshelf->getUrl();
+        } else if (isset($book)) {
+            $cancelUrl = $book->getUrl();
+        } else {
+            $cancelUrl = '/books';
+        }
+    ?>
+    <a href="{{ $cancelUrl }}" class="button outline">{{ trans('common.cancel') }}</a>
     <button type="submit" class="button">{{ trans('entities.books_save') }}</button>
 </div>
\ No newline at end of file
     <button type="submit" class="button">{{ trans('entities.books_save') }}</button>
 </div>
\ No newline at end of file
index a3fb1cfe11833591a5d1282aeda43fdce23f9eb9..c28ca8b3efd3b9ba7564265db77b10a9c5dbaebd 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace Tests;
 
 <?php namespace Tests;
 
+use BookStack\Entities\Bookshelf;
 use BookStack\Entities\Book;
 use BookStack\Entities\Chapter;
 use BookStack\Entities\Page;
 use BookStack\Entities\Book;
 use BookStack\Entities\Chapter;
 use BookStack\Entities\Page;
@@ -292,4 +293,29 @@ class EntityTest extends BrowserKitTest
         $this->assertEquals('parta-partb-partc', $book->slug);
     }
 
         $this->assertEquals('parta-partb-partc', $book->slug);
     }
 
+    public function test_shelf_cancel_creation_returns_to_correct_place()
+    {
+        $shelf = Bookshelf::first();
+
+        // Cancel button from shelf goes back to shelf
+        $this->asEditor()->visit($shelf->getUrl('/create-book'))
+            ->see('Cancel')
+            ->click('Cancel')
+            ->seePageIs($shelf->getUrl());
+
+        // Cancel button from books goes back to books
+        $this->asEditor()->visit('/create-book')
+            ->see('Cancel')
+            ->click('Cancel')
+            ->seePageIs('/books');
+
+        // Cancel button from book edit goes back to book
+        $book = Book::first();
+
+        $this->asEditor()->visit($book->getUrl('/edit'))
+            ->see('Cancel')
+            ->click('Cancel')
+            ->seePageIs($book->getUrl());
+    }
+
 }
 }