From e07fabc59564f52c3f139cc2faed6f5fe0276b3a Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 28 May 2019 10:50:38 +0300 Subject: [PATCH] Flextype Box Plugin: Admin #125 #117 - Templates Controller/Views implementation --- .../app/Controllers/TemplatesController.php | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/site/plugins/admin/app/Controllers/TemplatesController.php b/site/plugins/admin/app/Controllers/TemplatesController.php index 806c2e27..7b7df183 100644 --- a/site/plugins/admin/app/Controllers/TemplatesController.php +++ b/site/plugins/admin/app/Controllers/TemplatesController.php @@ -63,18 +63,42 @@ class TemplatesController extends Controller public function deleteProcess($request, $response, $args) { + $type = $request->getParsedBody()['type']; + if ($type == 'partial') { + $_type = '/templates/partials/'; + } else { + $_type = '/templates/'; + } + + $template_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '.html'; + + if (Filesystem::delete($template_path)) { + $this->flash->addMessage('success', __('admin_message_'.$type.'_deleted')); + } else { + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_deleted')); + } + + return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); } public function duplicateProcess($request, $response, $args) { - $template_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . '/templates/' . $request->getParsedBody()['template-id'] . '.html'; - $template_path_new = PATH['themes'] . '/' . $this->registry->get('settings.theme') . '/templates/' . $request->getParsedBody()['template-id'] . '-duplicate-' . date("Ymd_His") . '.html'; + $type = $request->getParsedBody()['type']; + + if ($type == 'partial') { + $_type = '/templates/partials/'; + } else { + $_type = '/templates/'; + } + + $template_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '.html'; + $template_path_new = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '-duplicate-' . date("Ymd_His") . '.html'; if (Filesystem::copy($template_path, $template_path_new)) { - $this->flash->addMessage('success', __('admin_message_templates_duplicated')); + $this->flash->addMessage('success', __('admin_message_'.$type.'_duplicated')); } else { - $this->flash->addMessage('error', __('admin_message_templates_was_not_duplicated')); + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_duplicated')); } return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index'));