]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Controllers/BookController.php
Comments: Added HTML filter on load, tinymce elem filtering
[bookstack] / app / Entities / Controllers / BookController.php
index 9b938d89a41c7f23fb311d5eedd86c2a0770a36a..412feca2fe5b24fee76cc1068ca3583dbcccae04 100644 (file)
@@ -7,7 +7,6 @@ use BookStack\Activity\ActivityType;
 use BookStack\Activity\Models\View;
 use BookStack\Activity\Tools\UserEntityWatchOptions;
 use BookStack\Entities\Models\Bookshelf;
-use BookStack\Entities\Models\Page;
 use BookStack\Entities\Repos\BookRepo;
 use BookStack\Entities\Tools\BookContents;
 use BookStack\Entities\Tools\Cloner;
@@ -25,15 +24,11 @@ use Throwable;
 
 class BookController extends Controller
 {
-    protected BookRepo $bookRepo;
-    protected ShelfContext $shelfContext;
-    protected ReferenceFetcher $referenceFetcher;
-
-    public function __construct(ShelfContext $entityContextManager, BookRepo $bookRepo, ReferenceFetcher $referenceFetcher)
-    {
-        $this->bookRepo = $bookRepo;
-        $this->shelfContext = $entityContextManager;
-        $this->referenceFetcher = $referenceFetcher;
+    public function __construct(
+        protected ShelfContext $shelfContext,
+        protected BookRepo $bookRepo,
+        protected ReferenceFetcher $referenceFetcher
+    ) {
     }
 
     /**
@@ -82,14 +77,8 @@ class BookController extends Controller
 
         $this->setPageTitle(trans('entities.books_create'));
 
-        $templates = Page::visible()
-            ->where('template', '=', true)
-            ->orderBy('name', 'asc')
-            ->get();
-
         return view('books.create', [
             'bookshelf' => $bookshelf,
-            'templates' => $templates,
         ]);
     }
 
@@ -103,11 +92,11 @@ class BookController extends Controller
     {
         $this->checkPermission('book-create-all');
         $validated = $this->validate($request, [
-            'name'        => ['required', 'string', 'max:255'],
-            'description' => ['string', 'max:1000'],
-            'image'       => array_merge(['nullable'], $this->getImageValidationRules()),
-            'tags'        => ['array'],
-            'default_template'  => ['nullable', 'exists:pages,id'], 
+            'name'                => ['required', 'string', 'max:255'],
+            'description_html'    => ['string', 'max:2000'],
+            'image'               => array_merge(['nullable'], $this->getImageValidationRules()),
+            'tags'                => ['array'],
+            'default_template_id' => ['nullable', 'integer'],
         ]);
 
         $bookshelf = null;
@@ -149,7 +138,7 @@ class BookController extends Controller
             'bookParentShelves' => $bookParentShelves,
             'watchOptions'      => new UserEntityWatchOptions(user(), $book),
             'activity'          => $activities->entityActivity($book, 20, 1),
-            'referenceCount'    => $this->referenceFetcher->getPageReferenceCountToEntity($book),
+            'referenceCount'    => $this->referenceFetcher->getReferenceCountToEntity($book),
         ]);
     }
 
@@ -162,12 +151,7 @@ class BookController extends Controller
         $this->checkOwnablePermission('book-update', $book);
         $this->setPageTitle(trans('entities.books_edit_named', ['bookName' => $book->getShortName()]));
 
-        $templates = Page::visible()
-            ->where('template', '=', true)
-            ->orderBy('name', 'asc')
-            ->get();
-
-        return view('books.edit', ['book' => $book, 'current' => $book, 'templates' => $templates]);
+        return view('books.edit', ['book' => $book, 'current' => $book]);
     }
 
     /**
@@ -183,11 +167,11 @@ class BookController extends Controller
         $this->checkOwnablePermission('book-update', $book);
 
         $validated = $this->validate($request, [
-            'name'        => ['required', 'string', 'max:255'],
-            'description' => ['string', 'max:1000'],
-            'image'       => array_merge(['nullable'], $this->getImageValidationRules()),
-            'tags'        => ['array'],
-            'default_template'  => ['nullable', 'exists:pages,id'], 
+            'name'                => ['required', 'string', 'max:255'],
+            'description_html'    => ['string', 'max:2000'],
+            'image'               => array_merge(['nullable'], $this->getImageValidationRules()),
+            'tags'                => ['array'],
+            'default_template_id' => ['nullable', 'integer'],
         ]);
 
         if ($request->has('image_reset')) {