Skip to content

Commit ab68594

Browse files
author
CaffeineSheep
committed
first attempt at implementing default template
1 parent 9a405d6 commit ab68594

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

app/Entities/Repos/PageRepo.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ public function getById(int $id, array $relations = ['book']): Page
6363
/**
6464
* Get a page its book and own slug.
6565
*
66-
* @throws NotFoundException
66+
* @throws NotFoundException if $allowNull is false
6767
*/
68-
public function getBySlug(string $bookSlug, string $pageSlug): Page
68+
public function getBySlug(string $bookSlug, string $pageSlug, bool $allowNull = false): Page|null
6969
{
7070
$page = Page::visible()->whereSlugs($bookSlug, $pageSlug)->first();
7171

72-
if (!$page) {
72+
if (!$page && !$allowNull) {
7373
throw new NotFoundException(trans('errors.page_not_found'));
7474
}
7575

@@ -133,13 +133,22 @@ public function getUserDraft(Page $page): ?PageRevision
133133
*/
134134
public function getNewDraftPage(Entity $parent)
135135
{
136-
$page = (new Page())->forceFill([
136+
137+
$defaultTemplatePage = $this->getBySlug("general", "symbol-template", true);
138+
139+
$newPageAttributes= [
137140
'name' => trans('entities.pages_initial_name'),
138141
'created_by' => user()->id,
139142
'owned_by' => user()->id,
140143
'updated_by' => user()->id,
141144
'draft' => true,
142-
]);
145+
];
146+
147+
if ($defaultTemplatePage) {
148+
$newPageAttributes['html'] = $defaultTemplatePage->html;
149+
}
150+
151+
$page = (new Page())->forceFill($newPageAttributes);
143152

144153
if ($parent instanceof Chapter) {
145154
$page->chapter_id = $parent->id;

0 commit comments

Comments
 (0)