@@ -63,13 +63,13 @@ public function getById(int $id, array $relations = ['book']): Page
63
63
/**
64
64
* Get a page its book and own slug.
65
65
*
66
- * @throws NotFoundException
66
+ * @throws NotFoundException if $allowNull is false
67
67
*/
68
- public function getBySlug (string $ bookSlug , string $ pageSlug ): Page
68
+ public function getBySlug (string $ bookSlug , string $ pageSlug, bool $ allowNull = false ): Page | null
69
69
{
70
70
$ page = Page::visible ()->whereSlugs ($ bookSlug , $ pageSlug )->first ();
71
71
72
- if (!$ page ) {
72
+ if (!$ page && ! $ allowNull ) {
73
73
throw new NotFoundException (trans ('errors.page_not_found ' ));
74
74
}
75
75
@@ -133,13 +133,22 @@ public function getUserDraft(Page $page): ?PageRevision
133
133
*/
134
134
public function getNewDraftPage (Entity $ parent )
135
135
{
136
- $ page = (new Page ())->forceFill ([
136
+
137
+ $ defaultTemplatePage = $ this ->getBySlug ("general " , "symbol-template " , true );
138
+
139
+ $ newPageAttributes = [
137
140
'name ' => trans ('entities.pages_initial_name ' ),
138
141
'created_by ' => user ()->id ,
139
142
'owned_by ' => user ()->id ,
140
143
'updated_by ' => user ()->id ,
141
144
'draft ' => true ,
142
- ]);
145
+ ];
146
+
147
+ if ($ defaultTemplatePage ) {
148
+ $ newPageAttributes ['html ' ] = $ defaultTemplatePage ->html ;
149
+ }
150
+
151
+ $ page = (new Page ())->forceFill ($ newPageAttributes );
143
152
144
153
if ($ parent instanceof Chapter) {
145
154
$ page ->chapter_id = $ parent ->id ;
0 commit comments