From 1064a94147b1d07b81d13262aa84b4bd309f3977 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 28 May 2019 17:57:07 +0300 Subject: [PATCH] Flextype Box Plugin: Admin #125 #117 - Templates Controller/Views implementation --- .../app/Controllers/TemplatesController.php | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/site/plugins/admin/app/Controllers/TemplatesController.php b/site/plugins/admin/app/Controllers/TemplatesController.php index 5018d0e5..e6ac3188 100644 --- a/site/plugins/admin/app/Controllers/TemplatesController.php +++ b/site/plugins/admin/app/Controllers/TemplatesController.php @@ -89,12 +89,46 @@ class TemplatesController extends Controller public function rename($request, $response, $args) { - + return $this->view->render($response, + 'plugins/admin/views/templates/extends/templates/rename.html', [ + 'menu_item' => 'templates', + 'types' => ['partial' => __('admin_partial'), 'template' => __('admin_template')], + 'id_current' => $request->getQueryParams()['id'], + 'type_current' => (($request->getQueryParams()['type'] && $request->getQueryParams()['type'] == 'partial') ? 'partial' : 'template'), + 'links' => [ + 'templates' => [ + 'link' => $this->router->pathFor('admin.templates.index'), + 'title' => __('admin_templates'), + 'attributes' => ['class' => 'navbar-item active'] + ], + ] + ]); } public function renameProcess($request, $response, $args) { + $type = $request->getParsedBody()['type_current']; + if ($type == 'partial') { + $_type = '/templates/partials/'; + } else { + $_type = '/templates/'; + } + + if (!Filesystem::has(PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id'] . '.html')) { + if (Filesystem::rename( + PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id_current'] . '.html', + PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id'] . '.html') + ) { + $this->flash->addMessage('success', __('admin_message_'.$type.'_renamed')); + } else { + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_renamed')); + } + } else { + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_renamed')); + } + + return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); } public function deleteProcess($request, $response, $args)