+ $page = $this->pageRepo->getNewDraftPage($parent);
+ $this->pageRepo->publishDraft($page, [
+ 'name' => $request->get('name'),
+ 'html' => ''
+ ]);
+
+ return redirect($page->getUrl('/edit'));
+ }
+
+ /**
+ * Show form to continue editing a draft page.
+ * @throws NotFoundException
+ */
+ public function editDraft(string $bookSlug, int $pageId)
+ {
+ $draft = $this->pageRepo->getById($pageId);
+ $this->checkOwnablePermission('page-create', $draft->getParent());
+ $this->setPageTitle(trans('entities.pages_edit_draft'));
+
+ $draftsEnabled = $this->isSignedIn();
+ $templates = $this->pageRepo->getTemplates(10);
+
+ return view('pages.edit', [
+ 'page' => $draft,
+ 'book' => $draft->book,
+ 'isDraft' => true,
+ 'draftsEnabled' => $draftsEnabled,
+ 'templates' => $templates,
+ ]);
+ }
+
+ /**
+ * Store a new page by changing a draft into a page.
+ * @throws NotFoundException
+ * @throws ValidationException
+ */
+ public function store(Request $request, string $bookSlug, int $pageId)
+ {
+ $this->validate($request, [
+ 'name' => 'required|string|max:255'
+ ]);
+ $draftPage = $this->pageRepo->getById($pageId);
+ $this->checkOwnablePermission('page-create', $draftPage->getParent());
+
+ $page = $this->pageRepo->publishDraft($draftPage, $request->all());