FEATURE: add support for writing blog posts

This commit is contained in:
Michal Kváček
2016-08-16 00:52:09 +02:00
parent debe80a314
commit 6f799f00bb
3 changed files with 116 additions and 10 deletions
+24 -9
View File
@@ -3,6 +3,7 @@ namespace Modules\Blog\Article\Handlers;
use App\Enumerations\ModulesHandlerToId;
use App\Handlers\Handler;
use App\Http\Controllers\Admin\EditContent;
use App\Http\Controllers\Controller;
use App\Http\Requests\Request;
use App\Models\Content;
@@ -23,15 +24,18 @@ class Article extends Handler
return Controller::VisitorsView($content->template, ['page' => $content]);
}
/**
* Load some extra data for content management form?
*
* @param Content $content
*
* @return mixed
*/
public static function loadExtraData(Content $content)
public static function getExtendedFormInputsCreate()
{
$sections = parent::getExtendedFormInputsCreate();
$sections['basicInfo'] = 'article::admin.content.basicInfo';
return $sections;
}
public static function getExtendedFormInputsEdit()
{
return self::getExtendedFormInputsCreate();
}
/**
@@ -45,6 +49,7 @@ class Article extends Handler
*/
public static function createNew(Content &$content, Request $request)
{
$content->module_settings = json_encode(['allowComments' => (int)$request->has('allowComments')]);
}
/**
@@ -61,7 +66,17 @@ class Article extends Handler
*/
public static function edit(Content &$content, Request $request, $revisionID)
{
// TODO: Implement edit() method.
$fields = ['allowComments' => 'allowComments'];
// get data and try to save them
$data = EditContent::getFields($request, $fields);
$data['allowComments'] = (int) $data['allowComments'];
list($revision, $changedColumns) = $content->updateWithHistory($fields, $data, $revisionID);
// return amount of changed columns
return $changedColumns;
}
/**
@@ -1,4 +1,6 @@
<?php
return [
'allowComments' => 'Allow comments?',
'new' => 'Write new',
'overview' => 'All articles'
];
@@ -0,0 +1,89 @@
<div class="row">
<div class="columns large-6">
<label>
@lang('admin/contents.field_title')
<input type="text" name="title" class="slug-source" placeholder="@lang('admin/contents.field_title')"
value="{{old('title', $page->title)}}" />
</label>
</div>
<div class="columns large-4">
<label>
@lang('admin/contents.field_url')
<input type="text" name="url" class="slug-target" placeholder="@lang('admin/contents.field_url')"
value="{{old('url', $page->url)}}" />
@if (isset($errors) && $errors->has('url'))
<div class="callout alert">
{{ $errors->first('url') }}
</div>
@endif
</label>
</div>
<div class="column large-2 text-center">
<label>
@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" />
</label>
</div>
</div>
<div class="row">
<div class="columns large-6">
<label>
<select name="status">
@foreach($contentStatuses as $status => $translation)
<option value="{{$status}}" @if(old('status', $page->status) == $status) selected @endif>
{{$translation}}
</option>
@endforeach
</select>
</label>
@if (isset($errors) && $errors->has('status'))
<div class="callout alert">
{{ $errors->first('status') }}
</div>
@endif
</div>
<div class="column large-6">
<label>
@lang('article::article.allowComments')
<input type="checkbox" value="1" @if(old('allowComments', isset($page->module_settings->allowComments) ? $page->module_settings->allowComments : true)) checked @endif name="allowComments" />
</label>
</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 class="row">
<div class="columns large-12">
<label>
<textarea name="pageContent" id="pageContent" class="wysiwyg-editor">
{{old('pageContent', $page->content)}}
</textarea>
</label>
</div>
</div>