FEATURE: add support for categories into content save/edit
This commit is contained in:
@@ -4,16 +4,14 @@ namespace App\Http\Controllers\Admin;
|
|||||||
use App\Enumerations\ActiveContentStatuses;
|
use App\Enumerations\ActiveContentStatuses;
|
||||||
use App\Events\CreateNewContent as CreateNewContentEvent;
|
use App\Events\CreateNewContent as CreateNewContentEvent;
|
||||||
use App\Http\Requests\CreateNewContentRequest;
|
use App\Http\Requests\CreateNewContentRequest;
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use App\Models\ContentHasFile;
|
|
||||||
use App\Models\Directory;
|
|
||||||
use App\Models\File;
|
use App\Models\File;
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
use App\Models\Template;
|
use App\Models\Template;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
use Modules\Categories\Entities\Category;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
class CreateNewContent extends Controller
|
class CreateNewContent extends Controller
|
||||||
@@ -43,7 +41,6 @@ class CreateNewContent extends Controller
|
|||||||
*/
|
*/
|
||||||
public function getNew($moduleId)
|
public function getNew($moduleId)
|
||||||
{
|
{
|
||||||
|
|
||||||
$module = Module::findOrFail($moduleId);
|
$module = Module::findOrFail($moduleId);
|
||||||
$statuses = ActiveContentStatuses::getWithTranslations();
|
$statuses = ActiveContentStatuses::getWithTranslations();
|
||||||
|
|
||||||
@@ -51,6 +48,13 @@ class CreateNewContent extends Controller
|
|||||||
->select(['template_name', 'name', 'description'])
|
->select(['template_name', 'name', 'description'])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
// add categories, if supported
|
||||||
|
$categories = [];
|
||||||
|
if ($module->support_categories) {
|
||||||
|
$categories = Category::where('module_id', $moduleId)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
// create default content object
|
// create default content object
|
||||||
$this->content->status = Content::STATUS_DRAFT;
|
$this->content->status = Content::STATUS_DRAFT;
|
||||||
|
|
||||||
@@ -59,6 +63,8 @@ class CreateNewContent extends Controller
|
|||||||
'contentStatuses' => $statuses,
|
'contentStatuses' => $statuses,
|
||||||
'templates' => $templates,
|
'templates' => $templates,
|
||||||
'moduleId' => $moduleId,
|
'moduleId' => $moduleId,
|
||||||
|
'module' => $module,
|
||||||
|
'categories' => $categories,
|
||||||
'page' => $this->content,
|
'page' => $this->content,
|
||||||
'rootPages' => $this->content->getOverview()
|
'rootPages' => $this->content->getOverview()
|
||||||
->get(),
|
->get(),
|
||||||
@@ -102,6 +108,7 @@ class CreateNewContent extends Controller
|
|||||||
$page->status = $request->status;
|
$page->status = $request->status;
|
||||||
$page->template = $request->template;
|
$page->template = $request->template;
|
||||||
$page->module_handler = $module->handler;
|
$page->module_handler = $module->handler;
|
||||||
|
$page->category_id = $request->category;
|
||||||
|
|
||||||
if ($request->parentPage) {
|
if ($request->parentPage) {
|
||||||
$page->parent_id = $request->parentPage;
|
$page->parent_id = $request->parentPage;
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ use App\Http\Requests\Request;
|
|||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use App\Models\ContentHistory;
|
use App\Models\ContentHistory;
|
||||||
use App\Models\File;
|
use App\Models\File;
|
||||||
|
use App\Models\Module;
|
||||||
use App\Models\Template;
|
use App\Models\Template;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
use Modules\Categories\Entities\Category;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
class EditContent extends Controller
|
class EditContent extends Controller
|
||||||
@@ -55,16 +57,27 @@ class EditContent extends Controller
|
|||||||
|
|
||||||
$allModules = ModulesHandlerToId::getWithTranslations();
|
$allModules = ModulesHandlerToId::getWithTranslations();
|
||||||
$moduleId = $allModules[$page->module_handler];
|
$moduleId = $allModules[$page->module_handler];
|
||||||
|
$module = Module::findOrFail($moduleId);
|
||||||
|
|
||||||
$templates = Template::where('module_id', $moduleId)
|
$templates = Template::where('module_id', $moduleId)
|
||||||
->select(['template_name', 'name', 'description'])
|
->select(['template_name', 'name', 'description'])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
// add categories, if supported
|
||||||
|
$categories = [];
|
||||||
|
if ($module->support_categories) {
|
||||||
|
$categories = Category::where('module_id', $moduleId)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
$history = $this->history->getStructuredHistoryOf($page);
|
$history = $this->history->getStructuredHistoryOf($page);
|
||||||
|
|
||||||
// render view
|
// render view
|
||||||
return view('admin.content.edit', [
|
return view('admin.content.edit', [
|
||||||
'contentStatuses' => $statuses,
|
'contentStatuses' => $statuses,
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
|
'module' => $module,
|
||||||
|
'categories' => $categories,
|
||||||
'rootPages' => $page->getOverview()
|
'rootPages' => $page->getOverview()
|
||||||
->where('contents.id', '!=', $page->id)
|
->where('contents.id', '!=', $page->id)
|
||||||
->get(),
|
->get(),
|
||||||
@@ -121,7 +134,8 @@ class EditContent extends Controller
|
|||||||
'content' => 'pageContent',
|
'content' => 'pageContent',
|
||||||
'parent_id' => 'parentPage',
|
'parent_id' => 'parentPage',
|
||||||
'status' => 'status',
|
'status' => 'status',
|
||||||
'title_photo' => 'titlePhotoFilename'
|
'title_photo' => 'titlePhotoFilename',
|
||||||
|
'category_id' => 'category'
|
||||||
];
|
];
|
||||||
|
|
||||||
// save new values with history
|
// save new values with history
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class Content extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'user_id',
|
'user_id',
|
||||||
'parent_id',
|
'parent_id',
|
||||||
|
'category_id',
|
||||||
'language',
|
'language',
|
||||||
'module_handler',
|
'module_handler',
|
||||||
'published_from',
|
'published_from',
|
||||||
@@ -260,7 +261,7 @@ class Content extends Model
|
|||||||
|
|
||||||
if (trim($fieldValue) != $request[$fieldRequest]) {
|
if (trim($fieldValue) != $request[$fieldRequest]) {
|
||||||
|
|
||||||
$this->saveHistory();
|
$this->saveHistory($revisionId, $fieldRequest, $fieldValue, $request);
|
||||||
|
|
||||||
// save change into database
|
// save change into database
|
||||||
if ($commonField) {
|
if ($commonField) {
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddCategorySupport extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$platform = Schema::getConnection()
|
||||||
|
->getDoctrineSchemaManager()
|
||||||
|
->getDatabasePlatform();
|
||||||
|
$platform->registerDoctrineTypeMapping('enum', 'string');
|
||||||
|
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->integer('category_id', false, true)
|
||||||
|
->comment('FK to table categories')
|
||||||
|
->after('module_handler')
|
||||||
|
->nullable(true)
|
||||||
|
->default(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->foreign('category_id')
|
||||||
|
->references('id')
|
||||||
|
->on('categories')
|
||||||
|
->onDelete('set null')
|
||||||
|
->onUpdate('cascade');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$platform = Schema::getConnection()
|
||||||
|
->getDoctrineSchemaManager()
|
||||||
|
->getDatabasePlatform();
|
||||||
|
$platform->registerDoctrineTypeMapping('enum', 'string');
|
||||||
|
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->dropForeign('contents_category_id_foreign');
|
||||||
|
$table->dropColumn('category_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ return [
|
|||||||
"alreadyHomepage" => "Domovská stránka",
|
"alreadyHomepage" => "Domovská stránka",
|
||||||
"appearance" => "Vzhled",
|
"appearance" => "Vzhled",
|
||||||
"basicInfo" => "Základní informace",
|
"basicInfo" => "Základní informace",
|
||||||
|
"category" => "Kategorie",
|
||||||
"content" => "Obsah stránky",
|
"content" => "Obsah stránky",
|
||||||
"deletePage" => "Smazat",
|
"deletePage" => "Smazat",
|
||||||
"edit" => "Editace :name",
|
"edit" => "Editace :name",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ return [
|
|||||||
'status_protected' => 'Protected',
|
'status_protected' => 'Protected',
|
||||||
'status_public' => 'Public',
|
'status_public' => 'Public',
|
||||||
'new' => 'Create new :name',
|
'new' => 'Create new :name',
|
||||||
|
'category' => 'Category',
|
||||||
'edit' => 'Edit :name',
|
'edit' => 'Edit :name',
|
||||||
'editPlain' => 'Edit',
|
'editPlain' => 'Edit',
|
||||||
'content' => 'Page content',
|
'content' => 'Page content',
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ return [
|
|||||||
'columnIs_homepage' => 'Homepage',
|
'columnIs_homepage' => 'Homepage',
|
||||||
'columnParentPage' => 'Parent page',
|
'columnParentPage' => 'Parent page',
|
||||||
'columnTitlePhotoFilename' => 'Title photo',
|
'columnTitlePhotoFilename' => 'Title photo',
|
||||||
|
'columnCategory' => 'Kategorie',
|
||||||
'emptyValue' => '<em>none</em>',
|
'emptyValue' => '<em>none</em>',
|
||||||
'changedFromTo' => 'Changed from <del>:from</del> to <ins>:to</ins>',
|
'changedFromTo' => 'Changed from <del>:from</del> to <ins>:to</ins>',
|
||||||
'numOfChanges' => 'One change|:count changes',
|
'numOfChanges' => 'One change|:count changes',
|
||||||
|
|||||||
@@ -25,7 +25,9 @@
|
|||||||
<label>
|
<label>
|
||||||
@lang('admin/contents.lockUrl')<br />
|
@lang('admin/contents.lockUrl')<br />
|
||||||
|
|
||||||
<input type="checkbox" value="1" id="lockUrl" @if(old('lockUrl') || ($page->id > 0 && \Illuminate\Support\Str::slug($page->title) != $page->url)) checked @endif name="lockUrl" />
|
<input type="checkbox" value="1" id="lockUrl"
|
||||||
|
@if(old('lockUrl') || ($page->id > 0 && \Illuminate\Support\Str::slug($page->title) != $page->url)) checked
|
||||||
|
@endif name="lockUrl" />
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -68,6 +70,25 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if($module->support_categories && count($categories))
|
||||||
|
<div class="column large-12">
|
||||||
|
<label>
|
||||||
|
@lang('admin/contents.category')
|
||||||
|
|
||||||
|
<select name="category">
|
||||||
|
<option value=""> ---</option>
|
||||||
|
@foreach($categories as $category)
|
||||||
|
<option value="{{$category->id}}"
|
||||||
|
@if($category->id == old('category', $page->category_id)) selected @endif>
|
||||||
|
{{str_repeat(' - ', $category->real_depth)}} {{$category->name}}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
Reference in New Issue
Block a user