From 53741c9ed17ca85ad477327cf3fa3edaf5b5742e Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 8 Jun 2019 11:56:11 +0300 Subject: [PATCH] Flextype Box Plugin: Admin #125 #117 - fixes and refactoring --- .../app/Controllers/EntriesController.php | 61 +++++++++---------- .../templates/content/entries/index.html | 4 +- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/site/plugins/admin/app/Controllers/EntriesController.php b/site/plugins/admin/app/Controllers/EntriesController.php index 57463938..8dc7810e 100644 --- a/site/plugins/admin/app/Controllers/EntriesController.php +++ b/site/plugins/admin/app/Controllers/EntriesController.php @@ -41,7 +41,7 @@ class EntriesController extends Controller // Set Entries ID in parts if (isset($query['id'])) { - $parts = explode("/", $query); + $parts = explode("/", $query['id']); } else { $parts = [0 => '']; } @@ -532,21 +532,22 @@ class EntriesController extends Controller public function edit(Request $request, Response $response) { - // Get Entry ID - $id = $request->getQueryParams()['id']; - $_id = $id; - if ($_id == null) { - $_id = [0 => '']; + // Get Query Params + $query = $request->getQueryParams(); + + // Set Entries ID in parts + if (isset($query['id'])) { + $parts = explode("/", $query['id']); } else { - $_id = explode("/", $id); + $parts = [0 => '']; } // Get Entry type $type = $request->getQueryParams()['type']; // Get Entry - $entry = $this->entries->fetch($id); + $entry = $this->entries->fetch($this->getEntryID($query)); // Fieldsets for current entry template $fieldsets_path = PATH['site'] . '/fieldsets/' . (isset($entry['fieldset']) ? $entry['fieldset'] : 'default') . '.json'; @@ -558,26 +559,26 @@ class EntriesController extends Controller $response, 'plugins/admin/views/templates/content/entries/source.html', [ - 'parts' => $_id, - 'i' => count($_id), - 'last' => Arr::last($_id), - 'id' => $id, + 'parts' => $parts, + 'i' => count($parts), + 'last' => Arr::last($parts), + 'id' => $this->getEntryID($query), 'data' => JsonParser::encode($entry), 'type' => $type, 'menu_item' => 'entries', 'links' => [ 'edit_entry' => [ - 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $id, + 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query). '&type=editor', 'title' => __('admin_content'), 'attributes' => ['class' => 'navbar-item'] ], 'edit_entry_media' => [ - 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=media', + 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=media', 'title' => __('admin_media'), 'attributes' => ['class' => 'navbar-item'] ], 'edit_entry_source' => [ - 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=source', + 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=source', 'title' => __('admin_source'), 'attributes' => ['class' => 'navbar-item active'] ], @@ -596,27 +597,25 @@ class EntriesController extends Controller $response, 'plugins/admin/views/templates/content/entries/media.html', [ - 'parts' => $_id, - 'i' => count($_id), - 'last' => Arr::last($_id), - - 'id' => $id, - 'files' => $this->getMediaList($id, true), - + 'parts' => $parts, + 'i' => count($parts), + 'last' => Arr::last($parts), + 'id' => $this->getEntryID($query), + 'files' => $this->getMediaList($this->getEntryID($query), true), 'menu_item' => 'entries', 'links' => [ 'edit_entry' => [ - 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $id, + 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=editor', 'title' => __('admin_content'), 'attributes' => ['class' => 'navbar-item'] ], 'edit_entry_media' => [ - 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=media', + 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=media', 'title' => __('admin_media'), 'attributes' => ['class' => 'navbar-item active'] ], 'edit_entry_source' => [ - 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=source', + 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=source', 'title' => __('admin_source'), 'attributes' => ['class' => 'navbar-item'] ], @@ -635,24 +634,24 @@ class EntriesController extends Controller $response, 'plugins/admin/views/templates/content/entries/edit.html', [ - 'parts' => $_id, - 'i' => count($_id), - 'last' => Arr::last($_id), + 'parts' => $parts, + 'i' => count($parts), + 'last' => Arr::last($parts), 'form' => $this->fetchForm($fieldsets, $entry, $request), 'menu_item' => 'entries', 'links' => [ 'edit_entry' => [ - 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $id, + 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=editor', 'title' => __('admin_content'), 'attributes' => ['class' => 'navbar-item active'] ], 'edit_entry_media' => [ - 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=media', + 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=media', 'title' => __('admin_media'), 'attributes' => ['class' => 'navbar-item'] ], 'edit_entry_source' => [ - 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=source', + 'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=source', 'title' => __('admin_source'), 'attributes' => ['class' => 'navbar-item'] ], diff --git a/site/plugins/admin/views/templates/content/entries/index.html b/site/plugins/admin/views/templates/content/entries/index.html index 69428b16..aee8c77e 100644 --- a/site/plugins/admin/views/templates/content/entries/index.html +++ b/site/plugins/admin/views/templates/content/entries/index.html @@ -14,7 +14,7 @@ {% set entries = entries_fetch_all(entry.slug, 'slug', 'ASC') %} - + {% if entry.fieldset %} {% set fieldset_path = PATH_SITE ~ '/fieldsets/' ~ entry.fieldset ~ '.json' %} {% if filesystem_has(fieldset_path) %} @@ -37,7 +37,7 @@
- {{ tr('admin_edit') }} + {{ tr('admin_edit') }}