1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-28 23:40:41 +02:00

Flextype Box Plugin: Admin #125 #117

- fixes and refactoring
This commit is contained in:
Awilum
2019-06-08 12:29:18 +03:00
parent fec8f31aad
commit cc9edc33bf
2 changed files with 14 additions and 13 deletions

View File

@@ -112,6 +112,7 @@ class EntriesController extends Controller
'entries_list' => $this->entries->fetchAll($this->getEntryID($query), 'date', 'DESC'),
'menu_item' => 'entries',
'fieldsets' => $fieldsets,
'current_id' => $this->getEntryID($query),
'links' => [
'entries' => [
'link' => $this->router->pathFor('admin.entries.index'),
@@ -142,24 +143,24 @@ class EntriesController extends Controller
$data = $request->getParsedBody();
// Set parent entry
if ($data['parent_entry']) {
$parent_entry = '/' . $data['parent_entry'];
if ($data['current_id']) {
$parent_entry_id = $data['current_id'];
} else {
$parent_entry = '/';
$parent_entry_id = '';
}
// Set new entry name
$entry = $parent_entry . Text::safeString($data['slug'], '-', true);
$id = $parent_entry_id . '/' . Text::safeString($data['id'], '-', true);
// Check if new entry exists
if (!$this->entries->has($entry)) {
if (!$this->entries->has($id)) {
// Get fieldset
$fieldset = JsonParser::decode(Filesystem::read(PATH['site'] . '/' . '/fieldsets/' . $data['fieldset'] . '.json'));
$fieldset = JsonParser::decode(Filesystem::read(PATH['site'] . '/fieldsets/' . $data['fieldset'] . '.json'));
// We need to check if template for current fieldset is exists
// if template is not exist then default template will be used!
$template_path = PATH['site'] . '/' . '/templates/' . $data['fieldset'] . '.html';
$template_path = PATH['site'] . '/templates/' . $data['fieldset'] . '.html';
if (Filesystem::has($template_path)) {
$template = $data['fieldset'];
} else {
@@ -208,13 +209,13 @@ class EntriesController extends Controller
}
*/
if ($this->entries->create($entry, $default_data)) {
if ($this->entries->create($id, $default_data)) {
$this->flash->addMessage('success', __('admin_message_entry_created'));
} else {
$this->flash->addMessage('error', __('admin_message_entry_was_not_created'));
}
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $data['parent_entry']);
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $parent_entry_id);
}
}
@@ -225,7 +226,7 @@ class EntriesController extends Controller
$fieldsets = [];
// Get fieldsets files
$_fieldsets = Filesystem::listContents(PATH['site'] . '/' . '/fieldsets/');
$_fieldsets = Filesystem::listContents(PATH['site'] . '/fieldsets/');
// If there is any template file then go...
if (count($_fieldsets) > 0) {

View File

@@ -3,7 +3,7 @@
{% block content %}
<form method="post" id="form">
{{ csrf() }}
<input type="hidden" id="parent_entry" name="parent_entry" value="{{ entry }}">
<input type="hidden" id="current_id" name="current_id" value="{{ current_id }}">
<div class="row">
<div class="col-md-6">
<div class="form-group">
@@ -11,8 +11,8 @@
<input type="text" id="title" name="title" value="" class="form-control" required="required" data-validation="length required" data-validation-length="min1" data-validation-error-msg="{{ tr('admin_error_title_empty_input') }}">
</div>
<div class="form-group">
<label for="slug">{{ tr('admin_name') }}</label>
<input type="text" id="slug" name="slug" value="" class="form-control" required="required" data-validation="length required" data-validation-length="min1" data-validation-error-msg="{{ tr('admin_error_name_empty_input') }}">
<label for="id">{{ tr('admin_name') }}</label>
<input type="text" id="id" name="id" value="" class="form-control" required="required" data-validation="length required" data-validation-length="min1" data-validation-error-msg="{{ tr('admin_error_name_empty_input') }}">
</div>
<div class="form-group">
<label>{{ tr('admin_type') }}</label>