FEATURE: add saving templates to static pages
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
namespace Modules\StaticPages\Http\Controllers\Admin;
|
||||
|
||||
use App\Enumerations\ContentStatuses;
|
||||
use App\Enumerations\ModulesHandlerToId;
|
||||
use App\Models\Content;
|
||||
use App\Models\Template;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Modules\StaticPages\Http\Requests\CreateNewStaticPageRequest;
|
||||
|
||||
@@ -20,9 +22,16 @@ class CreateNewStaticPage extends Controller
|
||||
// we do not want to create deleted page
|
||||
unset($statuses[Content::STATUS_DELETED]);
|
||||
|
||||
$allModules = ModulesHandlerToId::getWithTranslations();
|
||||
$moduleId = $allModules[config('staticpages.handler')];
|
||||
$templates = Template::where('module_id', $moduleId)
|
||||
->select(['template_name', 'name', 'description'])
|
||||
->get();
|
||||
|
||||
// render view
|
||||
return view('staticpages::admin.new', [
|
||||
'contentStatuses' => $statuses,
|
||||
'templates' => $templates,
|
||||
'selectedStatus' => Content::STATUS_DRAFT
|
||||
]);
|
||||
}
|
||||
@@ -48,6 +57,7 @@ class CreateNewStaticPage extends Controller
|
||||
$page->content = $request->pageContent;
|
||||
$page->status = $request->status;
|
||||
$page->module_handler = config('staticpages.handler');
|
||||
$page->template = $request->template;
|
||||
|
||||
$page->save();
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
namespace Modules\StaticPages\Http\Controllers\Admin;
|
||||
|
||||
use App\Enumerations\ContentStatuses;
|
||||
use App\Enumerations\ModulesHandlerToId;
|
||||
use App\Models\Content;
|
||||
use App\Models\ContentHistory;
|
||||
use App\Models\Template;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Modules\StaticPages\Events\DeleteStaticPage;
|
||||
use Modules\StaticPages\Events\EditStaticPage as EditStaticPageEvent;
|
||||
@@ -40,12 +42,19 @@ class EditStaticPage extends Controller
|
||||
$page = Content::where('module_handler', config('staticpages.handler'))
|
||||
->findOrFail($id);
|
||||
|
||||
$allModules = ModulesHandlerToId::getWithTranslations();
|
||||
$moduleId = $allModules[config('staticpages.handler')];
|
||||
$templates = Template::where('module_id', $moduleId)
|
||||
->select(['template_name', 'name', 'description'])
|
||||
->get();
|
||||
|
||||
$history = $this->history->getStructuredHistoryOf($page);
|
||||
|
||||
// render view
|
||||
return view('staticpages::admin.edit', [
|
||||
'contentStatuses' => $statuses,
|
||||
'page' => $page,
|
||||
'templates' => $templates,
|
||||
'historySize' => count($history['changesets'])
|
||||
]);
|
||||
}
|
||||
@@ -75,6 +84,7 @@ class EditStaticPage extends Controller
|
||||
$fields = [
|
||||
'title' => 'title',
|
||||
'url' => 'url',
|
||||
'template' => 'template',
|
||||
'published_from' => 'publishedFrom',
|
||||
'published_to' => 'publishedTo',
|
||||
'meta_keywords' => 'metaKeywords',
|
||||
|
||||
@@ -15,6 +15,7 @@ class CreateNewStaticPageRequest extends Request
|
||||
return [
|
||||
'title' => 'required',
|
||||
'url' => 'required|unique:contents,url',
|
||||
'template' => 'required|exists:templates,template_name',
|
||||
'published_from' => 'date',
|
||||
'published_to' => 'date',
|
||||
'title_photo' => 'exists:files,id',
|
||||
|
||||
@@ -20,6 +20,7 @@ class EditStaticPageRequest extends Request
|
||||
return [
|
||||
'title' => 'required',
|
||||
'url' => 'required|unique:contents,url,'.$this->id,
|
||||
'template' => 'required|exists:templates,template_name',
|
||||
'published_from' => 'date',
|
||||
'published_to' => 'date',
|
||||
'title_photo' => 'exists:files,id',
|
||||
|
||||
@@ -27,6 +27,9 @@ return [
|
||||
'pageDeleted' => 'Page :name (:url) successfully deleted.',
|
||||
'nothingToEdit' => 'You did not submit any changes. Nothing was edited.',
|
||||
'successfullyEdited' => 'Edit successfull',
|
||||
'showHistory' => 'History (:count)'
|
||||
'showHistory' => 'History (:count)',
|
||||
'templatePath' => 'Static pages',
|
||||
'appearance' => 'Appearance',
|
||||
'template' => 'Template of this page'
|
||||
|
||||
];
|
||||
@@ -24,6 +24,9 @@
|
||||
<li class="tabs-title">
|
||||
<a href="#publication">@lang('staticpages::admin.publicationOptions')</a>
|
||||
</li>
|
||||
<li class="tabs-title">
|
||||
<a href="#appearance">@lang('staticpages::admin.appearance')</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tabs-content" data-tabs-content="static-page-controls">
|
||||
@@ -141,6 +144,31 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="appearance">
|
||||
<div class="row">
|
||||
<div class="columns large-12">
|
||||
<label>
|
||||
@lang('staticpages::admin.template')
|
||||
|
||||
<select name="template">
|
||||
@foreach($templates as $template)
|
||||
<option value="{{$template->template_name}}">
|
||||
{{$template->name}}
|
||||
@if($template->description != '')
|
||||
- {{str_limit($template->description, 60)}}
|
||||
@endif
|
||||
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
<li class="tabs-title">
|
||||
<a href="#publication">@lang('staticpages::admin.publicationOptions')</a>
|
||||
</li>
|
||||
<li class="tabs-title">
|
||||
<a href="#appearance">@lang('staticpages::admin.appearance')</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tabs-content" data-tabs-content="static-page-controls">
|
||||
@@ -57,9 +60,9 @@
|
||||
<label>
|
||||
<select name="status">
|
||||
@foreach($contentStatuses as $status => $translation)
|
||||
<option value="{{$status}}" @if($selectedStatus== $status) selected @endif>
|
||||
{{$translation}}
|
||||
</option>
|
||||
<option value="{{$status}}" @if($selectedStatus== $status) selected @endif>
|
||||
{{$translation}}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
@@ -141,6 +144,37 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="appearance">
|
||||
<div class="row">
|
||||
<div class="columns large-12">
|
||||
<label>
|
||||
@lang('staticpages::admin.template')
|
||||
|
||||
<select name="template">
|
||||
@foreach($templates as $template)
|
||||
<option value="{{$template->template_name}}">
|
||||
{{$template->name}}
|
||||
@if($template->description != '')
|
||||
- {{str_limit($template->description, 60)}}
|
||||
@endif
|
||||
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
@if (isset($errors) && $errors->has('template'))
|
||||
<div class="callout alert">
|
||||
{{ $errors->first('template') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@@ -154,6 +188,6 @@
|
||||
<script src="{{asset('../resources/assets/js/vendor/ckeditor/ckeditor.js')}}"></script>
|
||||
|
||||
<script type="application/javascript">
|
||||
CKEDITOR.replace('pageContent');
|
||||
CKEDITOR.replace ('pageContent');
|
||||
</script>
|
||||
@stop
|
||||
Reference in New Issue
Block a user