From 10b384ccb1ea929d7103e6320af2cd0478917669 Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 26 Dec 2019 00:38:48 +0300 Subject: [PATCH] feat(admin-plugin): add ability for redirect to the editor after creating #343 --- .../app/Controllers/EntriesController.php | 1 - .../app/Controllers/FieldsetsController.php | 22 +++++++++++-------- .../app/Controllers/SnippetsController.php | 13 ++++++++--- .../app/Controllers/TemplatesController.php | 16 +++++++++----- .../views/templates/content/entries/add.html | 19 ++++++++-------- .../templates/extends/fieldsets/add.html | 10 ++++++++- .../views/templates/extends/snippets/add.html | 10 ++++++++- .../extends/themes/templates/add.html | 10 ++++++++- 8 files changed, 70 insertions(+), 31 deletions(-) diff --git a/site/plugins/admin/app/Controllers/EntriesController.php b/site/plugins/admin/app/Controllers/EntriesController.php index ee20a7b3..eca65dc0 100644 --- a/site/plugins/admin/app/Controllers/EntriesController.php +++ b/site/plugins/admin/app/Controllers/EntriesController.php @@ -288,7 +288,6 @@ class EntriesController extends Controller } else { return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $parent_entry_id); } - } /** diff --git a/site/plugins/admin/app/Controllers/FieldsetsController.php b/site/plugins/admin/app/Controllers/FieldsetsController.php index 7e16b35f..2fa257bf 100644 --- a/site/plugins/admin/app/Controllers/FieldsetsController.php +++ b/site/plugins/admin/app/Controllers/FieldsetsController.php @@ -70,16 +70,17 @@ class FieldsetsController extends Controller public function addProcess($request, $response) { - $data = $request->getParsedBody(); + // Get data from POST + $post_data = $request->getParsedBody(); - Arr::delete($data, 'csrf_name'); - Arr::delete($data, 'csrf_value'); + Arr::delete($post_data, 'csrf_name'); + Arr::delete($post_data, 'csrf_value'); - $id = $this->slugify->slugify($data['id']); - $data = ['title' => $data['title'], + $id = $this->slugify->slugify($post_data['id']); + $data = ['title' => $post_data['title'], 'default_field' => 'title', - 'icon' => $data['icon'], - 'hide' => (bool) $data['hide'], + 'icon' => $post_data['icon'], + 'hide' => (bool) $post_data['hide'], 'sections' => [ 'main' => [ 'title' => 'admin_main', @@ -98,8 +99,11 @@ class FieldsetsController extends Controller } else { $this->flash->addMessage('error', __('admin_message_fieldset_was_not_created')); } - - return $response->withRedirect($this->router->pathFor('admin.fieldsets.index')); + if (isset($post_data['create-and-edit'])) { + return $response->withRedirect($this->router->pathFor('admin.fieldsets.edit') . '?id=' . $id); + } else { + return $response->withRedirect($this->router->pathFor('admin.fieldsets.index')); + } } public function edit($request, $response) diff --git a/site/plugins/admin/app/Controllers/SnippetsController.php b/site/plugins/admin/app/Controllers/SnippetsController.php index dc617dcb..b5c9c4af 100644 --- a/site/plugins/admin/app/Controllers/SnippetsController.php +++ b/site/plugins/admin/app/Controllers/SnippetsController.php @@ -87,15 +87,22 @@ class SnippetsController extends Controller */ public function addProcess(Request $request, Response $response) : Response { - $id = $this->slugify->slugify($request->getParsedBody()['id']); + // Get data from POST + $post_data = $request->getParsedBody(); - if ($this->snippets->create($id, '')) { + $id = $post_data['id']; + + if ($this->snippets->create($this->slugify->slugify($request->getParsedBody()['id']), '')) { $this->flash->addMessage('success', __('admin_message_snippet_created')); } else { $this->flash->addMessage('error', __('admin_message_snippet_was_not_created')); } - return $response->withRedirect($this->router->pathFor('admin.snippets.index')); + if (isset($post_data['create-and-edit'])) { + return $response->withRedirect($this->router->pathFor('admin.snippets.edit') . '?id=' . $id); + } else { + return $response->withRedirect($this->router->pathFor('admin.snippets.index')); + } } /** diff --git a/site/plugins/admin/app/Controllers/TemplatesController.php b/site/plugins/admin/app/Controllers/TemplatesController.php index 9983634c..19e146dd 100644 --- a/site/plugins/admin/app/Controllers/TemplatesController.php +++ b/site/plugins/admin/app/Controllers/TemplatesController.php @@ -108,12 +108,14 @@ class TemplatesController extends Controller */ public function addProcess(Request $request, Response $response) : Response { - $type = $request->getParsedBody()['type']; - $theme = $request->getParsedBody()['theme']; + // Get data from POST + $post_data = $request->getParsedBody(); - $id = $this->slugify->slugify($request->getParsedBody()['id']) . '.html'; + $id = $post_data['id']; + $type = $post_data['type']; + $theme = $post_data['theme']; - $file = PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $id; + $file = PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $this->slugify->slugify($id) . '.html'; if (! Filesystem::has($file)) { if (Filesystem::write( @@ -128,7 +130,11 @@ class TemplatesController extends Controller $this->flash->addMessage('error', __('admin_message_' . $type . '_was_not_created')); } - return $response->withRedirect($this->router->pathFor('admin.templates.index') . '?theme=' . $theme); + if (isset($post_data['create-and-edit'])) { + return $response->withRedirect($this->router->pathFor('admin.templates.edit') . '?theme=' . $theme . '&type=' . $type . '&id=' . $id); + } else { + return $response->withRedirect($this->router->pathFor('admin.templates.index')); + } } /** diff --git a/site/plugins/admin/views/templates/content/entries/add.html b/site/plugins/admin/views/templates/content/entries/add.html index 600cdba6..7a4eff4b 100644 --- a/site/plugins/admin/views/templates/content/entries/add.html +++ b/site/plugins/admin/views/templates/content/entries/add.html @@ -39,16 +39,15 @@
- -
- - - -
+
+ + + +
diff --git a/site/plugins/admin/views/templates/extends/fieldsets/add.html b/site/plugins/admin/views/templates/extends/fieldsets/add.html index 242a179b..4b121b4c 100644 --- a/site/plugins/admin/views/templates/extends/fieldsets/add.html +++ b/site/plugins/admin/views/templates/extends/fieldsets/add.html @@ -43,7 +43,15 @@
- +
+ + + +
diff --git a/site/plugins/admin/views/templates/extends/snippets/add.html b/site/plugins/admin/views/templates/extends/snippets/add.html index 5ad11546..836b604a 100644 --- a/site/plugins/admin/views/templates/extends/snippets/add.html +++ b/site/plugins/admin/views/templates/extends/snippets/add.html @@ -11,7 +11,15 @@ {{ tr('admin_help_text_for_snippets_name') }}
- +
+ + + +
diff --git a/site/plugins/admin/views/templates/extends/themes/templates/add.html b/site/plugins/admin/views/templates/extends/themes/templates/add.html index bfd513ff..4534ad00 100644 --- a/site/plugins/admin/views/templates/extends/themes/templates/add.html +++ b/site/plugins/admin/views/templates/extends/themes/templates/add.html @@ -19,7 +19,15 @@
- +
+ + + +