mirror of
https://github.com/flextype/flextype.git
synced 2025-08-29 16:00:15 +02:00
- Templates Controller/Views implementation
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\Text\Text;
|
||||
use function Flextype\Component\I18n\__;
|
||||
|
||||
class TemplatesController extends Controller
|
||||
@@ -33,12 +34,47 @@ class TemplatesController extends Controller
|
||||
|
||||
public function add($request, $response, $args)
|
||||
{
|
||||
|
||||
return $this->view->render($response,
|
||||
'plugins/admin/views/templates/extends/templates/add.html', [
|
||||
'menu_item' => 'templates',
|
||||
'links' => [
|
||||
'templates' => [
|
||||
'link' => $this->router->pathFor('admin.templates.index'),
|
||||
'title' => __('admin_templates'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function addProcess($request, $response, $args)
|
||||
{
|
||||
$type = $request->getParsedBody()['type'];
|
||||
|
||||
if ($type == 'partial') {
|
||||
$_type = '/templates/partials/';
|
||||
} else {
|
||||
$_type = '/templates/';
|
||||
}
|
||||
|
||||
$id = Text::safeString($request->getParsedBody()['id'], '-', true) . '.html';
|
||||
|
||||
$file = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $id;
|
||||
|
||||
if (!Filesystem::has($file)) {
|
||||
if (Filesystem::write(
|
||||
$file,
|
||||
""
|
||||
)) {
|
||||
$this->flash->addMessage('success', __('admin_message_'.$type.'_created'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_created'));
|
||||
}
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_created'));
|
||||
}
|
||||
|
||||
return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index'));
|
||||
}
|
||||
|
||||
public function edit($request, $response, $args)
|
||||
@@ -71,9 +107,9 @@ class TemplatesController extends Controller
|
||||
$_type = '/templates/';
|
||||
}
|
||||
|
||||
$template_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '.html';
|
||||
$file_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '.html';
|
||||
|
||||
if (Filesystem::delete($template_path)) {
|
||||
if (Filesystem::delete($file_path)) {
|
||||
$this->flash->addMessage('success', __('admin_message_'.$type.'_deleted'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_deleted'));
|
||||
@@ -92,10 +128,10 @@ class TemplatesController extends Controller
|
||||
$_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';
|
||||
$file_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '.html';
|
||||
$file_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)) {
|
||||
if (Filesystem::copy($file_path, $file_path_new)) {
|
||||
$this->flash->addMessage('success', __('admin_message_'.$type.'_duplicated'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_duplicated'));
|
||||
|
Reference in New Issue
Block a user