Issue #1863 fixed
This commit is contained in:
parent
dd1ca9336b
commit
b4319e1f38
|
|
@ -13,23 +13,26 @@ use DB;
|
|||
*/
|
||||
class CMSPageDataGrid extends DataGrid
|
||||
{
|
||||
protected $index = 'id'; //the column that needs to be treated as index column
|
||||
protected $index = 'id';
|
||||
|
||||
protected $sortOrder = 'desc'; //asc or desc
|
||||
protected $sortOrder = 'desc';
|
||||
|
||||
public function prepareQueryBuilder()
|
||||
{
|
||||
$queryBuilder = DB::table('cms_pages')->select('id', 'url_key', 'page_title', 'channel_id', 'locale_id');
|
||||
$queryBuilder = DB::table('cms_pages')
|
||||
->select('cms_pages.id', 'cms_page_translations.page_title', 'cms_page_translations.url_key')
|
||||
->leftJoin('cms_page_translations', function($leftJoin) {
|
||||
$leftJoin->on('cms_pages.id', '=', 'cms_page_translations.cms_page_id')
|
||||
->where('cms_page_translations.locale', app()->getLocale());
|
||||
});
|
||||
|
||||
$this->addFilter('id', 'cms_pages.id');
|
||||
|
||||
$this->setQueryBuilder($queryBuilder);
|
||||
}
|
||||
|
||||
public function addColumns()
|
||||
{
|
||||
$channels = app('Webkul\Core\Repositories\ChannelRepository');
|
||||
|
||||
$locales = app('Webkul\Core\Repositories\LocaleRepository');
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'id',
|
||||
'label' => trans('admin::app.datagrid.id'),
|
||||
|
|
@ -39,15 +42,6 @@ class CMSPageDataGrid extends DataGrid
|
|||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'url_key',
|
||||
'label' => trans('admin::app.datagrid.url-key'),
|
||||
'type' => 'string',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'page_title',
|
||||
'label' => trans('admin::app.cms.pages.page-title'),
|
||||
|
|
@ -58,45 +52,26 @@ class CMSPageDataGrid extends DataGrid
|
|||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'locale_id',
|
||||
'label' => trans('admin::app.cms.pages.locale'),
|
||||
'type' => 'number',
|
||||
'searchable' => false,
|
||||
'index' => 'url_key',
|
||||
'label' => trans('admin::app.datagrid.url-key'),
|
||||
'type' => 'string',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true,
|
||||
'wrapper' => function($row) use($locales) {
|
||||
$localeCode = $locales->find($row->locale_id)->code;
|
||||
|
||||
return $row->locale_id.' ('. $localeCode. ')';
|
||||
}
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'channel_id',
|
||||
'label' => trans('admin::app.cms.pages.channel'),
|
||||
'type' => 'number',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'filterable' => true,
|
||||
'wrapper' => function($row) use($channels) {
|
||||
$channelCode = $channels->find($row->channel_id)->name;
|
||||
|
||||
return $row->channel_id.' ('. $channelCode. ')';
|
||||
}
|
||||
'filterable' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function prepareActions() {
|
||||
$this->addAction([
|
||||
'title' => 'Edit CMSPage',
|
||||
'method' => 'GET', // use GET request only for redirect purposes
|
||||
'method' => 'GET',
|
||||
'route' => 'admin.cms.edit',
|
||||
'icon' => 'icon pencil-lg-icon'
|
||||
]);
|
||||
|
||||
$this->addAction([
|
||||
'title' => 'Delete CMSPage',
|
||||
'method' => 'POST', // use GET request only for redirect purposes
|
||||
'method' => 'POST',
|
||||
'route' => 'admin.cms.delete',
|
||||
'icon' => 'icon trash-icon'
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -726,7 +726,6 @@ Route::group(['middleware' => ['web']], function () {
|
|||
'view' => 'admin::cms.index'
|
||||
])->name('admin.cms.index');
|
||||
|
||||
Route::get('preview/{url_key}', 'Webkul\CMS\Http\Controllers\Admin\PageController@preview')->name('admin.cms.preview');
|
||||
|
||||
Route::get('create', 'Webkul\CMS\Http\Controllers\Admin\PageController@create')->defaults('_config', [
|
||||
'view' => 'admin::cms.create'
|
||||
|
|
@ -736,11 +735,11 @@ Route::group(['middleware' => ['web']], function () {
|
|||
'redirect' => 'admin.cms.index'
|
||||
])->name('admin.cms.store');
|
||||
|
||||
Route::get('update/{id}', 'Webkul\CMS\Http\Controllers\Admin\PageController@edit')->defaults('_config', [
|
||||
Route::get('edit/{id}', 'Webkul\CMS\Http\Controllers\Admin\PageController@edit')->defaults('_config', [
|
||||
'view' => 'admin::cms.edit'
|
||||
])->name('admin.cms.edit');
|
||||
|
||||
Route::post('update/{id}', 'Webkul\CMS\Http\Controllers\Admin\PageController@update')->defaults('_config', [
|
||||
Route::post('edit/{id}', 'Webkul\CMS\Http\Controllers\Admin\PageController@update')->defaults('_config', [
|
||||
'redirect' => 'admin.cms.index'
|
||||
])->name('admin.cms.update');
|
||||
|
||||
|
|
|
|||
|
|
@ -1142,13 +1142,13 @@ return [
|
|||
'pages' => [
|
||||
'general' => 'General',
|
||||
'seo' => 'SEO',
|
||||
'pages' => 'Page',
|
||||
'title' => 'pages',
|
||||
'pages' => 'Pages',
|
||||
'title' => 'Pages',
|
||||
'add-title' => 'Add Page',
|
||||
'content' => 'Content',
|
||||
'url-key' => 'URL Key',
|
||||
'channel' => 'Channel',
|
||||
'locale' => 'Locale',
|
||||
'channel' => 'Channels',
|
||||
'locale' => 'Locales',
|
||||
'create-btn-title' => 'Save Page',
|
||||
'edit-title' => 'Edit Page',
|
||||
'edit-btn-title' => 'Save Page',
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
<div class="page-header">
|
||||
<div class="page-title">
|
||||
<h1>
|
||||
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i>
|
||||
<i class="icon angle-left-icon back-link" @click="redirectBack('{{ url('/admin/dashboard') }}')"></i>
|
||||
|
||||
{{ __('admin::app.cms.pages.pages') }}
|
||||
{{ __('admin::app.cms.pages.add-title') }}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
|
|
@ -28,6 +28,9 @@
|
|||
|
||||
<div class="form-container">
|
||||
@csrf()
|
||||
|
||||
{!! view_render_event('bagisto.admin.cms.pages.create_form_accordian.general.before') !!}
|
||||
|
||||
<accordian :title="'{{ __('admin::app.cms.pages.general') }}'" :active="true">
|
||||
<div slot="body">
|
||||
<div class="control-group" :class="[errors.has('page_title') ? 'has-error' : '']">
|
||||
|
|
@ -38,16 +41,7 @@
|
|||
<span class="control-error" v-if="errors.has('page_title')">@{{ errors.first('page_title') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('url_key') ? 'has-error' : '']">
|
||||
<label for="url-key" class="required">{{ __('admin::app.cms.pages.url-key') }}</label>
|
||||
|
||||
<input type="text" class="control" name="url_key" v-validate="'required'" value="{{ old('url-key') }}" data-vv-as=""{{ __('admin::app.cms.pages.url-key') }}"" v-slugify>
|
||||
|
||||
<span class="control-error" v-if="errors.has('url_key')">@{{ errors.first('url_key') }}</span>
|
||||
</div>
|
||||
|
||||
@inject('channels', 'Webkul\Core\Repositories\ChannelRepository')
|
||||
@inject('locales', 'Webkul\Core\Repositories\LocaleRepository')
|
||||
|
||||
<div class="control-group" :class="[errors.has('channels[]') ? 'has-error' : '']">
|
||||
<label for="url-key" class="required">{{ __('admin::app.cms.pages.channel') }}</label>
|
||||
|
|
@ -61,77 +55,56 @@
|
|||
<span class="control-error" v-if="errors.has('channels[]')">@{{ errors.first('channels[]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('locales[]') ? 'has-error' : '']">
|
||||
<label for="url-key" class="required">{{ __('admin::app.cms.pages.locale') }}</label>
|
||||
|
||||
<select type="text" class="control" name="locales[]" v-validate="'required'" value="{{ old('locale[]') }}" data-vv-as=""{{ __('admin::app.cms.pages.locale') }}"" multiple="multiple">
|
||||
@foreach($locales->all() as $locale)
|
||||
<option value="{{ $locale->id }}">{{ $locale->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
<span class="control-error" v-if="errors.has('locales[]')">@{{ errors.first('locales[]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('html_content') ? 'has-error' : '']">
|
||||
<label for="html_content" class="required">{{ __('admin::app.cms.pages.content') }}</label>
|
||||
|
||||
<textarea type="text" class="control" id="content" name="html_content" v-validate="'required'" value="{{ old('html_content') }}" data-vv-as=""{{ __('admin::app.cms.pages.content') }}""></textarea>
|
||||
|
||||
{!! __('admin::app.cms.pages.one-col') !!}
|
||||
{!! __('admin::app.cms.pages.two-col') !!}
|
||||
{!! __('admin::app.cms.pages.three-col') !!}
|
||||
|
||||
<div class="mt-10 mb-10">
|
||||
<a target="_blank" href="{{ route('ui.helper.classes') }}" class="btn btn-sm btn-primary">
|
||||
{{ __('admin::app.cms.pages.helper-classes') }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<span class="control-error" v-if="errors.has('html_content')">@{{ errors.first('html_content') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</accordian>
|
||||
|
||||
{!! view_render_event('bagisto.admin.cms.pages.create_form_accordian.general.after') !!}
|
||||
|
||||
|
||||
{!! view_render_event('bagisto.admin.cms.pages.create_form_accordian.seo.before') !!}
|
||||
|
||||
<accordian :title="'{{ __('admin::app.cms.pages.seo') }}'" :active="true">
|
||||
<div slot="body">
|
||||
<div class="control-group" :class="[errors.has('meta_title') ? 'has-error' : '']">
|
||||
<label for="meta_title" class="required">{{ __('admin::app.cms.pages.meta_title') }}</label>
|
||||
<div class="control-group">
|
||||
<label for="meta_title">{{ __('admin::app.cms.pages.meta_title') }}</label>
|
||||
|
||||
<input type="text" class="control" name="meta_title" v-validate="'required'" value="{{ old('meta_title') }}" data-vv-as=""{{ __('admin::app.cms.pages.meta_title') }}"">
|
||||
|
||||
<span class="control-error" v-if="errors.has('meta_title')">@{{ errors.first('meta_title') }}</span>
|
||||
<input type="text" class="control" name="meta_title" value="{{ old('meta_title') }}">
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('meta_keywords') ? 'has-error' : '']">
|
||||
<label for="meta_keywords" class="required">{{ __('admin::app.cms.pages.meta_keywords') }}</label>
|
||||
<div class="control-group" :class="[errors.has('url_key') ? 'has-error' : '']">
|
||||
<label for="url-key" class="required">{{ __('admin::app.cms.pages.url-key') }}</label>
|
||||
|
||||
<textarea type="text" class="control" name="meta_keywords" v-validate="'required'" value="{{ old('meta_keywords') }}" data-vv-as=""{{ __('admin::app.cms.pages.meta_keywords') }}""></textarea>
|
||||
<input type="text" class="control" name="url_key" v-validate="'required'" value="{{ old('url_key') }}" data-vv-as=""{{ __('admin::app.cms.pages.url-key') }}"" v-slugify>
|
||||
|
||||
<span class="control-error" v-if="errors.has('meta_keywords')">@{{ errors.first('meta_keywords') }}</span>
|
||||
<span class="control-error" v-if="errors.has('url_key')">@{{ errors.first('url_key') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('meta_description') ? 'has-error' : '']">
|
||||
<div class="control-group">
|
||||
<label for="meta_keywords">{{ __('admin::app.cms.pages.meta_keywords') }}</label>
|
||||
|
||||
<textarea type="text" class="control" name="meta_keywords" value="{{ old('meta_keywords') }}"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label for="meta_description">{{ __('admin::app.cms.pages.meta_description') }}</label>
|
||||
|
||||
<textarea type="text" class="control" name="meta_description" value="{{ old('meta_description') }}" data-vv-as=""{{ __('admin::app.cms.pages.meta_description') }}""></textarea>
|
||||
|
||||
<span class="control-error" v-if="errors.has('meta_description')">@{{ errors.first('meta_description') }}</span>
|
||||
<textarea type="text" class="control" name="meta_description" value="{{ old('meta_description') }}"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</accordian>
|
||||
|
||||
{!! view_render_event('bagisto.admin.cms.pages.create_form_accordian.seo.after') !!}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{{-- <modal id="showHelpers" :is-open="modalIds.showHelpers">
|
||||
<h3 slot="header">{{ __('admin::app.cms.pages.helper-classes') }}</h3>
|
||||
|
||||
<div slot="body">
|
||||
@include('ui::partials.helper-classes')
|
||||
</div>
|
||||
</modal> --}}
|
||||
@stop
|
||||
|
||||
@push('scripts')
|
||||
|
|
@ -142,7 +115,7 @@
|
|||
tinymce.init({
|
||||
selector: 'textarea#content',
|
||||
height: 200,
|
||||
width: "70%",
|
||||
width: "100%",
|
||||
plugins: 'image imagetools media wordcount save fullscreen code',
|
||||
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat | code',
|
||||
image_advtab: true,
|
||||
|
|
|
|||
|
|
@ -6,21 +6,35 @@
|
|||
|
||||
@section('content')
|
||||
<div class="content">
|
||||
<form method="POST" id="page-form" action="{{ route('admin.cms.edit', $page->id) }}" @submit.prevent="onSubmit">
|
||||
<?php $locale = request()->get('locale') ?: app()->getLocale(); ?>
|
||||
|
||||
<form method="POST" id="page-form" action="" @submit.prevent="onSubmit">
|
||||
|
||||
<div class="page-header">
|
||||
<div class="page-title">
|
||||
<h1>
|
||||
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i>
|
||||
<i class="icon angle-left-icon back-link" @click="redirectBack('{{ url('/admin/dashboard') }}')"></i>
|
||||
|
||||
{{ __('admin::app.cms.pages.pages') }}
|
||||
{{ __('admin::app.cms.pages.edit-title') }}
|
||||
</h1>
|
||||
|
||||
<div class="control-group">
|
||||
<select class="control" id="locale-switcher" onChange="window.location.href = this.value">
|
||||
@foreach (core()->getAllLocales() as $localeModel)
|
||||
|
||||
<option value="{{ route('admin.cms.edit', $page->id) . '?locale=' . $localeModel->code }}" {{ ($localeModel->code) == $locale ? 'selected' : '' }}>
|
||||
{{ $localeModel->name }}
|
||||
</option>
|
||||
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-action">
|
||||
<button id="preview" class="btn btn-lg btn-primary">
|
||||
<a href="{{ route('shop.cms.page', $page->translate($locale)['url_key']) }}" class="btn btn-lg btn-primary" target="_blank">
|
||||
{{ __('admin::app.cms.pages.preview') }}
|
||||
</button>
|
||||
</a>
|
||||
|
||||
<button type="submit" class="btn btn-lg btn-primary">
|
||||
{{ __('admin::app.cms.pages.edit-btn-title') }}
|
||||
|
|
@ -34,66 +48,72 @@
|
|||
@csrf()
|
||||
<accordian :title="'{{ __('admin::app.cms.pages.general') }}'" :active="true">
|
||||
<div slot="body">
|
||||
<div class="control-group" :class="[errors.has('page_title') ? 'has-error' : '']">
|
||||
<div class="control-group" :class="[errors.has('{{$locale}}[page_title]') ? 'has-error' : '']">
|
||||
<label for="page_title" class="required">{{ __('admin::app.cms.pages.page-title') }}</label>
|
||||
|
||||
<input type="text" class="control" name="page_title" v-validate="'required'" value="{{ $page->page_title ?? old('page_title') }}" data-vv-as=""{{ __('admin::app.cms.pages.page-title') }}"">
|
||||
<input type="text" class="control" name="{{$locale}}[page_title]" v-validate="'required'" value="{{ old($locale)['page_title'] ?? $page->translate($locale)['page_title'] }}" data-vv-as=""{{ __('admin::app.cms.pages.page-title') }}"">
|
||||
|
||||
<span class="control-error" v-if="errors.has('page_title')">@{{ errors.first('page_title') }}</span>
|
||||
<span class="control-error" v-if="errors.has('{{$locale}}[page_title]')">@{{ errors.first('{!!$locale!!}[page_title]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('url_key') ? 'has-error' : '']">
|
||||
<label for="url-key" class="required">{{ __('admin::app.cms.pages.url-key') }}</label>
|
||||
<div class="control-group" :class="[errors.has('channels[]') ? 'has-error' : '']">
|
||||
<label for="url-key" class="required">{{ __('admin::app.cms.pages.channel') }}</label>
|
||||
|
||||
<input type="text" class="control" name="url_key" v-validate="'required'" value="{{ $page->url_key ?? old('url_key') }}" data-vv-as=""{{ __('admin::app.cms.pages.url-key') }}"" disabled>
|
||||
<?php $selectedOptionIds = old('inventory_sources') ?: $page->channels->pluck('id')->toArray() ?>
|
||||
|
||||
<span class="control-error" v-if="errors.has('url_key')">@{{ errors.first('url_key') }}</span>
|
||||
<select type="text" class="control" name="channels[]" v-validate="'required'" value="{{ old('channel[]') }}" data-vv-as=""{{ __('admin::app.cms.pages.channel') }}"" multiple="multiple">
|
||||
@foreach(app('Webkul\Core\Repositories\ChannelRepository')->all() as $channel)
|
||||
<option value="{{ $channel->id }}" {{ in_array($channel->id, $selectedOptionIds) ? 'selected' : '' }}>
|
||||
{{ $channel->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
<span class="control-error" v-if="errors.has('channels[]')">@{{ errors.first('channels[]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('html_content') ? 'has-error' : '']">
|
||||
<div class="control-group" :class="[errors.has('{{$locale}}[html_content]') ? 'has-error' : '']">
|
||||
<label for="html_content" class="required">{{ __('admin::app.cms.pages.content') }}</label>
|
||||
|
||||
<textarea type="text" class="control" id="content" name="html_content" v-validate="'required'" data-vv-as=""{{ __('admin::app.cms.pages.content') }}"">{{ $page->html_content ?? old('html_content') }}</textarea>
|
||||
<textarea type="text" class="control" id="content" name="{{$locale}}[html_content]" v-validate="'required'" data-vv-as=""{{ __('admin::app.cms.pages.content') }}"">
|
||||
{{ old($locale)['html_content'] ?? $page->translate($locale)['html_content'] }}
|
||||
</textarea>
|
||||
|
||||
{!! __('admin::app.cms.pages.one-col') !!}
|
||||
{!! __('admin::app.cms.pages.two-col') !!}
|
||||
{!! __('admin::app.cms.pages.three-col') !!}
|
||||
|
||||
<div class="mt-10 mb-10">
|
||||
<a target="_blank" href="{{ route('ui.helper.classes') }}" class="btn btn-sm btn-primary">
|
||||
{{ __('admin::app.cms.pages.helper-classes') }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<span class="control-error" v-if="errors.has('html_content')">@{{ errors.first('html_content') }}</span>
|
||||
<span class="control-error" v-if="errors.has('{{$locale}}[html_content]')">@{{ errors.first('{!!$locale!!}[html_content]') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</accordian>
|
||||
|
||||
<accordian :title="'{{ __('admin::app.cms.pages.seo') }}'" :active="true">
|
||||
<div slot="body">
|
||||
<div class="control-group" :class="[errors.has('meta_title') ? 'has-error' : '']">
|
||||
<label for="meta_title" class="required">{{ __('admin::app.cms.pages.meta_title') }}</label>
|
||||
<div class="control-group">
|
||||
<label for="meta_title">{{ __('admin::app.cms.pages.meta_title') }}</label>
|
||||
|
||||
<input type="text" class="control" name="meta_title" v-validate="'required'" value="{{ $page->meta_title ?? old('meta_title') }}" data-vv-as=""{{ __('admin::app.cms.pages.meta_title') }}"">
|
||||
|
||||
<span class="control-error" v-if="errors.has('meta_title')">@{{ errors.first('meta_title') }}</span>
|
||||
<input type="text" class="control" name="{{$locale}}[meta_title]" value="{{ old($locale)['meta_title'] ?? $page->translate($locale)['meta_title'] }}">
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('meta_keywords') ? 'has-error' : '']">
|
||||
<label for="meta_keywords" class="required">{{ __('admin::app.cms.pages.meta_keywords') }}</label>
|
||||
<div class="control-group" :class="[errors.has('{{$locale}}[url_key]') ? 'has-error' : '']">
|
||||
<label for="url-key" class="required">{{ __('admin::app.cms.pages.url-key') }}</label>
|
||||
|
||||
<textarea type="text" class="control" name="meta_keywords" v-validate="'required'" data-vv-as=""{{ __('admin::app.cms.pages.meta_keywords') }}"">{{ $page->meta_keywords ?? old('meta_keywords') }}</textarea>
|
||||
<input type="text" class="control" name="{{$locale}}[url_key]" v-validate="'required'" value="{{ old($locale)['url_key'] ?? $page->translate($locale)['url_key'] }}" data-vv-as=""{{ __('admin::app.cms.pages.url-key') }}"">
|
||||
|
||||
<span class="control-error" v-if="errors.has('meta_keywords')">@{{ errors.first('meta_keywords') }}</span>
|
||||
<span class="control-error" v-if="errors.has('{{$locale}}[url_key]')">@{{ errors.first('{!!$locale!!}[url_key]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('meta_description') ? 'has-error' : '']">
|
||||
<div class="control-group">
|
||||
<label for="meta_keywords">{{ __('admin::app.cms.pages.meta_keywords') }}</label>
|
||||
|
||||
<textarea type="text" class="control" name="{{$locale}}[meta_keywords]">
|
||||
{{ old($locale)['meta_keywords'] ?? $page->translate($locale)['meta_keywords'] }}
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label for="meta_description">{{ __('admin::app.cms.pages.meta_description') }}</label>
|
||||
|
||||
<textarea type="text" class="control" name="meta_description" data-vv-as=""{{ __('admin::app.cms.pages.meta_description') }}"">{{ $page->meta_description ?? old('meta_description') }}</textarea>
|
||||
|
||||
<span class="control-error" v-if="errors.has('meta_description')">@{{ errors.first('meta_description') }}</span>
|
||||
<textarea type="text" class="control" name="{{$locale}}[meta_description]">
|
||||
{{ old($locale)['meta_description'] ?? $page->translate($locale)['meta_description'] }}
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</accordian>
|
||||
|
|
@ -108,27 +128,10 @@
|
|||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#preview').on('click', function(e) {
|
||||
var form = $('#page-form').serialize();
|
||||
// var url = '{{ route('admin.cms.preview', $page->id) }}' + '?' + form;
|
||||
var url = '{{ route('admin.cms.preview', $page->id) }}';
|
||||
|
||||
window.open(url, '_blank').focus();
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#channel-switcher, #locale-switcher').on('change', function (e) {
|
||||
$('#channel-switcher').val()
|
||||
var query = '?channel=' + $('#channel-switcher').val() + '&locale=' + $('#locale-switcher').val();
|
||||
|
||||
window.location.href = "{{ route('admin.cms.edit', $page->id) }}" + query;
|
||||
});
|
||||
|
||||
tinymce.init({
|
||||
selector: 'textarea#content',
|
||||
height: 200,
|
||||
width: "70%",
|
||||
width: "100%",
|
||||
plugins: 'image imagetools media wordcount save fullscreen code',
|
||||
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat | code',
|
||||
image_advtab: true,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
namespace Webkul\CMS\Contracts;
|
||||
|
||||
interface CMS
|
||||
interface CmsPage
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\CMS\Contracts;
|
||||
|
||||
interface CmsPageTranslation
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCmsPageTranslationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cms_page_translations', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('page_title');
|
||||
$table->string('url_key');
|
||||
$table->text('html_content')->nullable();
|
||||
$table->text('meta_title')->nullable();
|
||||
$table->text('meta_description')->nullable();
|
||||
$table->text('meta_keywords')->nullable();
|
||||
$table->string('locale');
|
||||
|
||||
$table->integer('cms_page_id')->unsigned();
|
||||
$table->unique(['cms_page_id', 'url_key', 'locale']);
|
||||
$table->foreign('cms_page_id')->references('id')->on('cms_pages')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('cms_page_translations');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class RemoveColumnsFromCmsPagesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('cms_pages', function (Blueprint $table) {
|
||||
$table->dropForeign('cms_pages_locale_id_foreign');
|
||||
$table->dropForeign('cms_pages_channel_id_foreign');
|
||||
$table->dropColumn(['url_key', 'html_content', 'page_title', 'meta_title', 'meta_description', 'meta_keywords', 'content', 'locale_id', 'channel_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('cms_pages', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCmsPageChannelsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cms_page_channels', function (Blueprint $table) {
|
||||
$table->integer('cms_page_id')->unsigned();
|
||||
$table->integer('channel_id')->unsigned();
|
||||
|
||||
$table->unique(['cms_page_id', 'channel_id']);
|
||||
$table->foreign('cms_page_id')->references('id')->on('cms_pages')->onDelete('cascade');
|
||||
$table->foreign('channel_id')->references('id')->on('channels')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('cms_page_channels');
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ namespace Webkul\CMS\Database\Seeders;
|
|||
|
||||
use Illuminate\Database\Seeder;
|
||||
use DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class CMSPagesTableSeeder extends Seeder
|
||||
{
|
||||
|
|
@ -13,101 +14,99 @@ class CMSPagesTableSeeder extends Seeder
|
|||
|
||||
DB::table('cms_pages')->insert([
|
||||
[
|
||||
'id' => '1',
|
||||
'id' => 1,
|
||||
'created_at' => Carbon::now(),
|
||||
'updated_at' => Carbon::now()
|
||||
], [
|
||||
'id' => 2,
|
||||
'created_at' => Carbon::now(),
|
||||
'updated_at' => Carbon::now()
|
||||
], [
|
||||
'id' => 3,
|
||||
'created_at' => Carbon::now(),
|
||||
'updated_at' => Carbon::now()
|
||||
], [
|
||||
'id' => 4,
|
||||
'created_at' => Carbon::now(),
|
||||
'updated_at' => Carbon::now()
|
||||
], [
|
||||
'id' => 5,
|
||||
'created_at' => Carbon::now(),
|
||||
'updated_at' => Carbon::now()
|
||||
], [
|
||||
'id' => 6,
|
||||
'created_at' => Carbon::now(),
|
||||
'updated_at' => Carbon::now()
|
||||
]
|
||||
]);
|
||||
|
||||
DB::table('cms_page_translations')->insert([
|
||||
[
|
||||
'locale' => 'en',
|
||||
'cms_page_id' => 1,
|
||||
'url_key' => 'about-us',
|
||||
'html_content' => '<div class="static-container one-column">
|
||||
'html_content' => '<div class="static-container">
|
||||
<div class="mb-5">About us page content</div>
|
||||
</div>',
|
||||
'page_title' => 'About Us',
|
||||
'meta_title' => 'about us',
|
||||
'meta_description' => '',
|
||||
'meta_keywords' => 'aboutus',
|
||||
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">About us page content</div>\r\n</div>",
|
||||
"meta_title": "about us",
|
||||
"page_title": "About Us",
|
||||
"meta_keywords": "aboutus ", "meta_description": ""}',
|
||||
'channel_id' => 1,
|
||||
'locale_id' => 1
|
||||
'meta_keywords' => 'aboutus'
|
||||
], [
|
||||
'id' => '2',
|
||||
'locale' => 'en',
|
||||
'cms_page_id' => 2,
|
||||
'url_key' => 'return-policy',
|
||||
'html_content' => '<div class="static-container one-column">
|
||||
'html_content' => '<div class="static-container">
|
||||
<div class="mb-5">Return policy page content</div>
|
||||
</div>',
|
||||
'page_title' => 'Return Policy',
|
||||
'meta_title' => 'return policy',
|
||||
'meta_description' => '',
|
||||
'meta_keywords' => 'return, policy',
|
||||
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Return policy page content</div>\r\n</div>",
|
||||
"meta_title": "return policy",
|
||||
"page_title": "Return Policy",
|
||||
"meta_keywords": "return, policy ", "meta_description": ""}',
|
||||
'channel_id' => 1,
|
||||
'locale_id' => 1
|
||||
'meta_keywords' => 'return, policy'
|
||||
], [
|
||||
'id' => '3',
|
||||
'locale' => 'en',
|
||||
'cms_page_id' => 3,
|
||||
'url_key' => 'refund-policy',
|
||||
'html_content' => '<div class="static-container one-column">
|
||||
'html_content' => '<div class="static-container">
|
||||
<div class="mb-5">Refund policy page content</div>
|
||||
</div>',
|
||||
'page_title' => 'Refund Policy',
|
||||
'meta_title' => 'Refund policy',
|
||||
'meta_description' => '',
|
||||
'meta_keywords' => 'refund, policy',
|
||||
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Refund policy page content</div>\r\n</div>",
|
||||
"meta_title": "Refund policy",
|
||||
"page_title": "Refund Policy",
|
||||
"meta_keywords": "refund,policy ", "meta_description": ""}',
|
||||
'channel_id' => 1,
|
||||
'locale_id' => 1
|
||||
'meta_keywords' => 'refund, policy'
|
||||
], [
|
||||
'id' => '4',
|
||||
'locale' => 'en',
|
||||
'cms_page_id' => 4,
|
||||
'url_key' => 'terms-conditions',
|
||||
'html_content' => '<div class="static-container one-column">
|
||||
'html_content' => '<div class="static-container">
|
||||
<div class="mb-5">Terms & conditions page content</div>
|
||||
</div>',
|
||||
'page_title' => 'Terms & Conditions',
|
||||
'meta_title' => 'Terms & Conditions',
|
||||
'meta_description' => '',
|
||||
'meta_keywords' => 'term, conditions',
|
||||
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Terms & conditions page content</div>\r\n</div>",
|
||||
"meta_title": "Terms & Conditions",
|
||||
"page_title": "Terms & Conditions",
|
||||
"meta_keywords": "terms, conditions ", "meta_description": ""}',
|
||||
'channel_id' => 1,
|
||||
'locale_id' => 1
|
||||
'meta_keywords' => 'term, conditions'
|
||||
], [
|
||||
'id' => '5',
|
||||
'locale' => 'en',
|
||||
'cms_page_id' => 5,
|
||||
'url_key' => 'terms-of-use',
|
||||
'html_content' => '<div class="static-container one-column">
|
||||
'html_content' => '<div class="static-container">
|
||||
<div class="mb-5">Terms of use page content</div>
|
||||
</div>',
|
||||
'page_title' => 'Terms of use',
|
||||
'meta_title' => 'Terms of use',
|
||||
'meta_description' => '',
|
||||
'meta_keywords' => 'term, use',
|
||||
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Terms of use page content</div>\r\n</div>",
|
||||
"meta_title": "Terms of use",
|
||||
"page_title": "Terms of use",
|
||||
"meta_keywords": "terms, use ", "meta_description": ""}',
|
||||
'channel_id' => 1,
|
||||
'locale_id' => 1
|
||||
'meta_keywords' => 'term, use'
|
||||
], [
|
||||
'id' => '6',
|
||||
'locale' => 'en',
|
||||
'cms_page_id' => 6,
|
||||
'url_key' => 'contact-us',
|
||||
'html_content' => '<div class="static-container one-column">
|
||||
'html_content' => '<div class="static-container">
|
||||
<div class="mb-5">Contact us page content</div>
|
||||
</div>',
|
||||
'page_title' => 'Contact Us',
|
||||
'meta_title' => 'Contact Us',
|
||||
'meta_description' => '',
|
||||
'meta_keywords' => 'contact, us',
|
||||
'content' => '{"html": "<div class=\"static-container one-column\">\r\n<div class=\"mb-5\">Contact us page content</div>\r\n</div>",
|
||||
"meta_title": "Contact Us",
|
||||
"page_title": "Contact Us",
|
||||
"meta_keywords": "contact, us ", "meta_description": ""}',
|
||||
'channel_id' => 1,
|
||||
'locale_id' => 1
|
||||
'meta_keywords' => 'contact, us'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,67 +3,49 @@
|
|||
namespace Webkul\CMS\Http\Controllers\Admin;
|
||||
|
||||
use Webkul\CMS\Http\Controllers\Controller;
|
||||
use Webkul\CMS\Repositories\CMSRepository as CMS;
|
||||
use Webkul\Core\Repositories\ChannelRepository as Channel;
|
||||
use Webkul\Core\Repositories\LocaleRepository as Locale;
|
||||
use Webkul\CMS\Repositories\CmsRepository;
|
||||
|
||||
/**
|
||||
* CMS controller
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class PageController extends Controller
|
||||
{
|
||||
/**
|
||||
* To hold the request variables from route file
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* To hold the channel reposotry instance
|
||||
*/
|
||||
protected $channel;
|
||||
|
||||
/**
|
||||
* To hold the locale reposotry instance
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* To hold the CMSRepository instance
|
||||
*
|
||||
* @var Object
|
||||
*/
|
||||
protected $cms;
|
||||
protected $cmsRepository;
|
||||
|
||||
public function __construct(Channel $channel, Locale $locale, CMS $cms)
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\CMS\Repositories\CmsRepository $cmsRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CmsRepository $cmsRepository)
|
||||
{
|
||||
/**
|
||||
* Pass the class instance through admin middleware
|
||||
*/
|
||||
// $this->middleware('auth:admin');
|
||||
|
||||
$this->middleware('admin');
|
||||
|
||||
/**
|
||||
* Channel repository instance
|
||||
*/
|
||||
$this->channel = $channel;
|
||||
|
||||
/**
|
||||
* Locale repository instance
|
||||
*/
|
||||
$this->locale = $locale;
|
||||
|
||||
/**
|
||||
* CMS repository instance
|
||||
*/
|
||||
$this->cms = $cms;
|
||||
$this->cmsRepository = $cmsRepository;
|
||||
|
||||
$this->_config = request('_config');
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the index page showing the static pages resources
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
|
@ -73,7 +55,7 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
|
|||
/**
|
||||
* To create a new CMS page
|
||||
*
|
||||
* @return view
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
|
|
@ -83,74 +65,22 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
|
|||
/**
|
||||
* To store a new CMS page in storage
|
||||
*
|
||||
* @return view
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = request()->all();
|
||||
|
||||
// part one of the validation in case partials pages were generated or generating partial pages
|
||||
$this->validate(request(), [
|
||||
'url_key' => ['required', 'unique:cms_page_translations,url_key', new \Webkul\Core\Contracts\Validations\Slug],
|
||||
'page_title' => 'required',
|
||||
'channels' => 'required',
|
||||
'locales' => 'required',
|
||||
'url_key' => 'required'
|
||||
'html_content' => 'required'
|
||||
]);
|
||||
|
||||
$page = $this->cmsRepository->create(request()->all());
|
||||
|
||||
$channels = $data['channels'];
|
||||
$locales = $data['locales'];
|
||||
|
||||
$this->validate(request(), [
|
||||
'html_content' => 'required|string',
|
||||
'page_title' => 'required|string',
|
||||
'meta_title' => 'required|string',
|
||||
'meta_description' => 'string',
|
||||
'meta_keywords' => 'required|string'
|
||||
]);
|
||||
|
||||
$data['content']['html'] = $data['html_content'];
|
||||
$data['content']['page_title'] = $data['page_title'];
|
||||
$data['content']['meta_keywords'] = $data['meta_keywords'];
|
||||
$data['content']['meta_title'] = $data['meta_title'];
|
||||
$data['content']['meta_description'] = $data['meta_description'];
|
||||
|
||||
$data['content'] = json_encode($data['content']);
|
||||
|
||||
$totalCount = 0;
|
||||
$actualCount = 0;
|
||||
|
||||
foreach ($channels as $channel) {
|
||||
foreach ($locales as $locale) {
|
||||
$pageFound = $this->cms->findOneWhere([
|
||||
'channel_id' => $channel,
|
||||
'locale_id' => $locale,
|
||||
'url_key' => $data['url_key']
|
||||
]);
|
||||
|
||||
$totalCount++;
|
||||
|
||||
$data['channel_id'] = $channel;
|
||||
|
||||
$data['locale_id'] = $locale;
|
||||
|
||||
if (! $pageFound) {
|
||||
$result = $this->cms->create($data);
|
||||
|
||||
if ($result) {
|
||||
$actualCount++;
|
||||
}
|
||||
}
|
||||
|
||||
unset($pageFound);
|
||||
}
|
||||
}
|
||||
|
||||
if (($actualCount != 0 && $totalCount != 0) && ($actualCount == $totalCount)) {
|
||||
session()->flash('success', trans('admin::app.cms.pages.create-success'));
|
||||
} else if (($actualCount != 0 && $totalCount != 0) && ($actualCount != $totalCount)) {
|
||||
session()->flash('warning', trans('admin::app.cms.pages.create-partial'));
|
||||
} else {
|
||||
session()->flash('error', trans('admin::app.cms.pages.create-failure'));
|
||||
}
|
||||
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'page']));
|
||||
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
}
|
||||
|
|
@ -158,105 +88,53 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
|
|||
/**
|
||||
* To edit a previously created CMS page
|
||||
*
|
||||
* @return view
|
||||
* @param integer $id
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$page = $this->cms->findOrFail($id);
|
||||
$page = $this->cmsRepository->findOrFail($id);
|
||||
|
||||
if (request()->has('channel') && request()->has('locale')) {
|
||||
$channel = $this->channel->findOneWhere([
|
||||
'code' => request()->input('channel')
|
||||
]);
|
||||
|
||||
$locale = $this->locale->findOneWhere([
|
||||
'code' => request()->input('locale')
|
||||
]);
|
||||
|
||||
$page = $this->cms->findOneWhere([
|
||||
'channel_id' => $channel->id,
|
||||
'locale_id' => $locale->id,
|
||||
'url_key' => $page->url_key
|
||||
]);
|
||||
|
||||
if (! $page) {
|
||||
$page = $this->cms->create([
|
||||
'url_key' => str_random(8),
|
||||
'channel' => $channel->code,
|
||||
'locale' => $locale->code
|
||||
]);
|
||||
|
||||
return redirect()->route('admin.cms.edit', $page->id);
|
||||
}
|
||||
} else {
|
||||
$page = $this->cms->findOrFail($id);
|
||||
}
|
||||
|
||||
return view($this->_config['view'])->with('page', $page);
|
||||
return view($this->_config['view'], compact('page'));
|
||||
}
|
||||
|
||||
/**
|
||||
* To update the previously created CMS page in storage
|
||||
*
|
||||
* @param Integer $id
|
||||
*
|
||||
* @return View
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$page = $this->cms->findOrFail($id);
|
||||
|
||||
$data = request()->all();
|
||||
$locale = request()->get('locale') ?: app()->getLocale();
|
||||
|
||||
$this->validate(request(), [
|
||||
'page_title' => 'required|string',
|
||||
'html_content' => 'required|string',
|
||||
'meta_title' => 'required|string',
|
||||
'meta_description' => 'string',
|
||||
'meta_keywords' => 'required|string'
|
||||
$locale . '.url_key' => ['required', new \Webkul\Core\Contracts\Validations\Slug, function ($attribute, $value, $fail) use ($id) {
|
||||
if (! $this->cmsRepository->isUrlKeyUnique($id, $value))
|
||||
$fail(trans('admin::app.response.already-taken', ['name' => 'Page']));
|
||||
}],
|
||||
$locale . '.page_title' => 'required',
|
||||
$locale . '.html_content' => 'required',
|
||||
'channels' => 'required'
|
||||
]);
|
||||
|
||||
$data['content']['html'] = $data['html_content'];
|
||||
$data['content']['page_title'] = $data['page_title'];
|
||||
$data['content']['meta_keywords'] = $data['meta_keywords'];
|
||||
$data['content']['meta_title'] = $data['meta_title'];
|
||||
$data['content']['meta_description'] = $data['meta_description'];
|
||||
$data['content'] = json_encode($data['content']);
|
||||
$this->cmsRepository->update(request()->all(), $id);
|
||||
|
||||
$result = $this->cms->update($data, $id);
|
||||
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Page']));
|
||||
|
||||
if ($result) {
|
||||
session()->flash('success', trans('admin::app.cms.pages.update-success'));
|
||||
} else {
|
||||
session()->flash('success', trans('admin::app.cms.pages.update-failure'));
|
||||
}
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
}
|
||||
|
||||
/**
|
||||
* To preview the content of the currently creating page or previously creating page
|
||||
*
|
||||
* @param Integer $id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function preview($id)
|
||||
{
|
||||
$page = $this->cms->findOrFail($id);
|
||||
|
||||
return view('shop::cms.page')->with('page', $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* To delete the previously create CMS page
|
||||
*
|
||||
* @param Integer $id
|
||||
* @param integer $id
|
||||
*
|
||||
* @return Response JSON
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$page = $this->cms->findOrFail($id);
|
||||
$page = $this->cmsRepository->findOrFail($id);
|
||||
|
||||
if ($page->delete()) {
|
||||
session()->flash('success', trans('admin::app.cms.pages.delete-success'));
|
||||
|
|
@ -272,7 +150,7 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
|
|||
/**
|
||||
* To mass delete the CMS resource from storage
|
||||
*
|
||||
* @return Response redirect
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function massDelete()
|
||||
{
|
||||
|
|
@ -281,13 +159,10 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
|
|||
if ($data['indexes']) {
|
||||
$pageIDs = explode(',', $data['indexes']);
|
||||
|
||||
$actualCount = count($pageIDs);
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ($pageIDs as $pageId) {
|
||||
|
||||
$page = $this->cms->find($pageId);
|
||||
$page = $this->cmsRepository->find($pageId);
|
||||
|
||||
if ($page) {
|
||||
$page->delete();
|
||||
|
|
@ -296,7 +171,7 @@ use Webkul\Core\Repositories\LocaleRepository as Locale;
|
|||
}
|
||||
}
|
||||
|
||||
if ($actualCount == $count) {
|
||||
if (count($pageIDs) == $count) {
|
||||
session()->flash('success', trans('admin::app.datagrid.mass-ops.delete-success', [
|
||||
'resource' => 'CMS Pages'
|
||||
]));
|
||||
|
|
|
|||
|
|
@ -3,66 +3,43 @@
|
|||
namespace Webkul\CMS\Http\Controllers\Shop;
|
||||
|
||||
use Webkul\CMS\Http\Controllers\Controller;
|
||||
use Webkul\CMS\Repositories\CMSRepository;
|
||||
use Webkul\Core\Repositories\LocaleRepository;
|
||||
use Webkul\CMS\Repositories\CmsRepository;
|
||||
|
||||
/**
|
||||
* PagePresenter controller
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class PagePresenterController extends Controller
|
||||
{
|
||||
/**
|
||||
* CMSRepository object
|
||||
* CmsRepository object
|
||||
*
|
||||
* @var Object
|
||||
*/
|
||||
protected $cmsRepository;
|
||||
|
||||
/**
|
||||
* LocaleRepository object
|
||||
*
|
||||
* @var Object
|
||||
*/
|
||||
protected $localeRepository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\CMS\Repositories\CMSRepository $cmsRepository
|
||||
* @param \Webkul\Core\Repositories\LocaleRepository $localeRepository
|
||||
* @param \Webkul\CMS\Repositories\CmsRepository $cmsRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
CMSRepository $cmsRepository,
|
||||
LocaleRepository $localeRepository
|
||||
)
|
||||
public function __construct(CmsRepository $cmsRepository)
|
||||
{
|
||||
$this->cmsRepository = $cmsRepository;
|
||||
|
||||
$this->localeRepository = $localeRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* To extract the page content and load it in the respective view file
|
||||
*
|
||||
* @param string $slug
|
||||
* @param string $urlKey
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function presenter($slug)
|
||||
public function presenter($urlKey)
|
||||
{
|
||||
$currentLocale = $this->localeRepository->findOneByField('code', app()->getLocale());
|
||||
|
||||
$page = $this->cmsRepository->findOneWhere([
|
||||
'url_key' => $slug,
|
||||
'locale_id' => $currentLocale->id,
|
||||
'channel_id' => core()->getCurrentChannel()->id
|
||||
]);
|
||||
|
||||
if (! $page)
|
||||
abort(404);
|
||||
$page = $this->cmsRepository->findByUrlKeyOrFail($urlKey);
|
||||
|
||||
return view('shop::cms.page')->with('page', $page);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\CMS\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\CMS\Contracts\CMS as CMSContract;
|
||||
|
||||
class CMS extends Model implements CMSContract
|
||||
{
|
||||
protected $table = 'cms_pages';
|
||||
|
||||
protected $fillable = ['content', 'meta_description', 'meta_title', 'page_title', 'meta_keywords', 'html_content', 'url_key', 'layout', 'channel_id', 'locale_id'];
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\CMS\Models;
|
||||
|
||||
use Webkul\Core\Eloquent\TranslatableModel;
|
||||
use Webkul\CMS\Contracts\CmsPage as CmsPageContract;
|
||||
use Webkul\Core\Models\ChannelProxy;
|
||||
|
||||
class CmsPage extends TranslatableModel implements CmsPageContract
|
||||
{
|
||||
protected $fillable = ['layout'];
|
||||
|
||||
public $translatedAttributes = ['content', 'meta_description', 'meta_title', 'page_title', 'meta_keywords', 'html_content', 'url_key'];
|
||||
|
||||
protected $with = ['translations'];
|
||||
|
||||
/**
|
||||
* Get the channels.
|
||||
*/
|
||||
public function channels()
|
||||
{
|
||||
return $this->belongsToMany(ChannelProxy::modelClass(), 'cms_page_channels');
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ namespace Webkul\CMS\Models;
|
|||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class CMSProxy extends ModelProxy
|
||||
class CmsPageProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\CMS\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\CMS\Contracts\CmsPageTranslation as CmsPageTranslationContract;
|
||||
|
||||
class CmsPageTranslation extends Model implements CmsPageTranslationContract
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['page_title', 'url_key', 'html_content', 'meta_title', 'meta_description', 'meta_keywords', 'locale', 'cms_page_id'];
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\CMS\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class CmsPageTranslationProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -3,15 +3,12 @@
|
|||
namespace Webkul\CMS\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Routing\Router;
|
||||
use Webkul\CMS\Providers\ModuleServiceProvider;
|
||||
|
||||
class CMSServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot(Router $router)
|
||||
public function boot()
|
||||
{
|
||||
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'cms');
|
||||
|
||||
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ use Konekt\Concord\BaseModuleServiceProvider;
|
|||
class ModuleServiceProvider extends BaseModuleServiceProvider
|
||||
{
|
||||
protected $models = [
|
||||
\Webkul\CMS\Models\CMS::class
|
||||
\Webkul\CMS\Models\CmsPage::class,
|
||||
\Webkul\CMS\Models\CmsPageTranslation::class
|
||||
];
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\CMS\Repositories;
|
||||
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Repositories\ChannelRepository as Channel;
|
||||
use Webkul\Core\Repositories\LocaleRepository as Locale;
|
||||
|
||||
/**
|
||||
* CMS Reposotory
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class CMSRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* To hold the channel reposotry instance
|
||||
*/
|
||||
protected $channel;
|
||||
|
||||
/**
|
||||
* To hold the locale reposotry instance
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
public function __construct(Channel $channel, Locale $locale, App $app)
|
||||
{
|
||||
$this->channel = $channel;
|
||||
|
||||
$this->locale = $locale;
|
||||
|
||||
parent::__construct($app);
|
||||
}
|
||||
/**
|
||||
* Specify Model class name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function model()
|
||||
{
|
||||
return 'Webkul\CMS\Contracts\CMS';
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
$result = $this->model->create($data);
|
||||
|
||||
if ($result) {
|
||||
return $result;
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\CMS\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Webkul\CMS\Models\CmsPageTranslation;
|
||||
|
||||
/**
|
||||
* CMS Reposotory
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CmsRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Specify Model class name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function model()
|
||||
{
|
||||
return 'Webkul\CMS\Contracts\CmsPage';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
Event::fire('cms.pages.create.before');
|
||||
|
||||
$model = $this->getModel();
|
||||
|
||||
foreach (core()->getAllLocales() as $locale) {
|
||||
foreach ($model->translatedAttributes as $attribute) {
|
||||
if (isset($data[$attribute]))
|
||||
$data[$locale->code][$attribute] = $data[$attribute];
|
||||
}
|
||||
}
|
||||
|
||||
$page = parent::create($data);
|
||||
|
||||
$page->channels()->sync($data['channels']);
|
||||
|
||||
Event::fire('cms.pages.create.after', $page);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param integer $id
|
||||
* @param string $attribute
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(array $data, $id, $attribute = "id")
|
||||
{
|
||||
$page = $this->find($id);
|
||||
|
||||
Event::fire('cms.pages.update.before', $id);
|
||||
|
||||
parent::update($data, $id, $attribute);
|
||||
|
||||
$page->channels()->sync($data['channels']);
|
||||
|
||||
Event::fire('cms.pages.update.after', $id);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks slug is unique or not based on locale
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $urlKey
|
||||
* @return boolean
|
||||
*/
|
||||
public function isUrlKeyUnique($id, $urlKey)
|
||||
{
|
||||
$exists = CmsPageTranslation::where('cms_page_id', '<>', $id)
|
||||
->where('url_key', $urlKey)
|
||||
->limit(1)
|
||||
->select(\DB::raw(1))
|
||||
->exists();
|
||||
|
||||
return $exists ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive category from slug
|
||||
*
|
||||
* @param string $urlKey
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByUrlKeyOrFail($urlKey)
|
||||
{
|
||||
$page = $this->model->whereTranslation('url_key', $urlKey)->first();
|
||||
|
||||
if ($page)
|
||||
return $page;
|
||||
|
||||
throw (new ModelNotFoundException)->setModel(
|
||||
get_class($this->model), $urlKey
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,16 +18,6 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|||
*/
|
||||
class CategoryRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify Model class name
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue