1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-18 19:01:40 +02:00

feat(admin-plugin): add ability for redirect to the editor after creating #343

This commit is contained in:
Awilum
2019-12-26 00:38:48 +03:00
parent 1d3d0cf27b
commit 10b384ccb1
8 changed files with 70 additions and 31 deletions

View File

@@ -288,7 +288,6 @@ class EntriesController extends Controller
} else {
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $parent_entry_id);
}
}
/**

View File

@@ -70,16 +70,17 @@ class FieldsetsController extends Controller
public function addProcess($request, $response)
{
$data = $request->getParsedBody();
// Get data from POST
$post_data = $request->getParsedBody();
Arr::delete($data, 'csrf_name');
Arr::delete($data, 'csrf_value');
Arr::delete($post_data, 'csrf_name');
Arr::delete($post_data, 'csrf_value');
$id = $this->slugify->slugify($data['id']);
$data = ['title' => $data['title'],
$id = $this->slugify->slugify($post_data['id']);
$data = ['title' => $post_data['title'],
'default_field' => 'title',
'icon' => $data['icon'],
'hide' => (bool) $data['hide'],
'icon' => $post_data['icon'],
'hide' => (bool) $post_data['hide'],
'sections' => [
'main' => [
'title' => 'admin_main',
@@ -98,8 +99,11 @@ class FieldsetsController extends Controller
} else {
$this->flash->addMessage('error', __('admin_message_fieldset_was_not_created'));
}
return $response->withRedirect($this->router->pathFor('admin.fieldsets.index'));
if (isset($post_data['create-and-edit'])) {
return $response->withRedirect($this->router->pathFor('admin.fieldsets.edit') . '?id=' . $id);
} else {
return $response->withRedirect($this->router->pathFor('admin.fieldsets.index'));
}
}
public function edit($request, $response)

View File

@@ -87,15 +87,22 @@ class SnippetsController extends Controller
*/
public function addProcess(Request $request, Response $response) : Response
{
$id = $this->slugify->slugify($request->getParsedBody()['id']);
// Get data from POST
$post_data = $request->getParsedBody();
if ($this->snippets->create($id, '')) {
$id = $post_data['id'];
if ($this->snippets->create($this->slugify->slugify($request->getParsedBody()['id']), '')) {
$this->flash->addMessage('success', __('admin_message_snippet_created'));
} else {
$this->flash->addMessage('error', __('admin_message_snippet_was_not_created'));
}
return $response->withRedirect($this->router->pathFor('admin.snippets.index'));
if (isset($post_data['create-and-edit'])) {
return $response->withRedirect($this->router->pathFor('admin.snippets.edit') . '?id=' . $id);
} else {
return $response->withRedirect($this->router->pathFor('admin.snippets.index'));
}
}
/**

View File

@@ -108,12 +108,14 @@ class TemplatesController extends Controller
*/
public function addProcess(Request $request, Response $response) : Response
{
$type = $request->getParsedBody()['type'];
$theme = $request->getParsedBody()['theme'];
// Get data from POST
$post_data = $request->getParsedBody();
$id = $this->slugify->slugify($request->getParsedBody()['id']) . '.html';
$id = $post_data['id'];
$type = $post_data['type'];
$theme = $post_data['theme'];
$file = PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $id;
$file = PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $this->slugify->slugify($id) . '.html';
if (! Filesystem::has($file)) {
if (Filesystem::write(
@@ -128,7 +130,11 @@ class TemplatesController extends Controller
$this->flash->addMessage('error', __('admin_message_' . $type . '_was_not_created'));
}
return $response->withRedirect($this->router->pathFor('admin.templates.index') . '?theme=' . $theme);
if (isset($post_data['create-and-edit'])) {
return $response->withRedirect($this->router->pathFor('admin.templates.edit') . '?theme=' . $theme . '&type=' . $type . '&id=' . $id);
} else {
return $response->withRedirect($this->router->pathFor('admin.templates.index'));
}
}
/**

View File

@@ -39,16 +39,15 @@
</div>
</div>
<div class="form-group">
<div class="btn-group custom-btn-group">
<input type="submit" id="create" name="create" value="{{ tr('admin_create') }}" class="btn btn-black">
<button type="button" class="btn dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<input type="submit" id="create-and-edit" name="create-and-edit" value="{{ tr('admin_create_and_edit') }}" class="dropdown-item">
</div>
</div>
<div class="btn-group custom-btn-group">
<input type="submit" id="create" name="create" value="{{ tr('admin_create') }}" class="btn btn-black">
<button type="button" class="btn dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<input type="submit" id="create-and-edit" name="create-and-edit" value="{{ tr('admin_create_and_edit') }}" class="dropdown-item">
</div>
</div>
</div>
</div>
</div>

View File

@@ -43,7 +43,15 @@
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="submit" id="createFieldset" name="create_fieldset" value="{{ tr('admin_create') }}" class="btn btn-black">
<div class="btn-group custom-btn-group">
<input type="submit" id="create" name="create" value="{{ tr('admin_create') }}" class="btn btn-black">
<button type="button" class="btn dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<input type="submit" id="create-and-edit" name="create-and-edit" value="{{ tr('admin_create_and_edit') }}" class="dropdown-item">
</div>
</div>
</div>
</div>
</div>

View File

@@ -11,7 +11,15 @@
<small class="form-text text-muted">{{ tr('admin_help_text_for_snippets_name') }}</small>
</div>
<div class="form-group">
<input type="submit" id="createSnippet" name="create_snippet" value="{{ tr('admin_create') }}" class="btn btn-black">
<div class="btn-group custom-btn-group">
<input type="submit" id="create" name="create" value="{{ tr('admin_create') }}" class="btn btn-black">
<button type="button" class="btn dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<input type="submit" id="create-and-edit" name="create-and-edit" value="{{ tr('admin_create_and_edit') }}" class="dropdown-item">
</div>
</div>
</div>
</div>
</div>

View File

@@ -19,7 +19,15 @@
</select>
</div>
<div class="form-group">
<input type="submit" id="createTemplate" name="create_template" value="{{ tr('admin_create') }}" class="btn btn-black">
<div class="btn-group custom-btn-group">
<input type="submit" id="create" name="create" value="{{ tr('admin_create') }}" class="btn btn-black">
<button type="button" class="btn dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<input type="submit" id="create-and-edit" name="create-and-edit" value="{{ tr('admin_create_and_edit') }}" class="dropdown-item">
</div>
</div>
</div>
</div>
</div>