FEATURE: add customizable settings for create/edit/overview of content pages

This commit is contained in:
Michal Kváček
2016-09-24 02:55:51 +02:00
parent b7434d0a0b
commit 6d107d0881
10 changed files with 131 additions and 14 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace App\Handlers\Contracts;
use App\Models\Content;
/**
* Interface ContentTitles
*
* Classes which implement this interface get the ability to rewrite default text on edit/create/overview of content
* page.
*
* @package App\Handlers\Contracts
*/
interface ContentTitles
{
/**
* Get translated title for pages overview of given type.
*
* This value is used for rendering list of all content pages of given type in administration.
*
* @return string
*/
public static function getOverviewTitle();
/**
* Title displayed above for for creating new content page
*
* @return string
*/
public static function getCreateNewTitle();
/**
* Title for form displayed for editin content page
*
* @param Content $content
*
* @return mixed
*/
public static function getEditTitle(Content $content);
}
@@ -17,6 +17,13 @@ use Modules\Categories\Entities\Category;
use Pingpong\Modules\Facades\Module as ModuleInstance;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class CreateNewContent
*
* Controller for creating new content page.
*
* @package App\Http\Controllers\Admin\Contents
*/
class CreateNewContent extends Controller
{
/**
@@ -28,6 +35,14 @@ class CreateNewContent extends Controller
*/
private $content;
/**
* CreateNewContent constructor.
*
* Sets File and Content models into class variables
*
* @param File $file
* @param Content $content
*/
public function __construct(File $file, Content $content)
{
parent::__construct();
@@ -47,12 +62,19 @@ class CreateNewContent extends Controller
$module = Module::findOrFail($moduleId);
$statuses = ContentStatuses::getWithTranslations();
// set default page title
$pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]);
if (is_callable([$module->handler, 'getCreateNewTitle'])) {
$pageHeading = call_user_func([$module->handler, 'getCreateNewTitle']);
}
// get list of usable templates
$templates = Template::where('module_id', $moduleId)
->select(['template_name', 'name', 'description'])
->get();
$categoryModule = ModuleInstance::get('categories');
// add categories, if supported
$categoryModule = ModuleInstance::get('categories');
$categories = [];
if ($module->support_categories && $categoryModule->enabled()) {
$categories = Category::where('module_id', $moduleId)
@@ -64,6 +86,7 @@ class CreateNewContent extends Controller
// render view
return view('admin.content.new', [
'pageHeading' => $pageHeading,
'contentStatuses' => $statuses,
'templates' => $templates,
'moduleId' => $moduleId,
@@ -89,7 +112,6 @@ class CreateNewContent extends Controller
*/
public function postNew(CreateNewContentRequest $request, $moduleId)
{
$page = new Content();
try {
$module = Module::findOrFail($moduleId);
} catch (NotFoundHttpException $e) {
@@ -99,6 +121,10 @@ class CreateNewContent extends Controller
->with('error', trans('admin/contents.invalidModule'));
}
// create new page
$page = new Content();
$page->template = $request->template;
// setup basic info
$page->user_id = \Auth::user()->id;
$page->language = LaravelLocalization::getCurrentLocale();
@@ -110,10 +136,10 @@ class CreateNewContent extends Controller
$page->meta_description = $request->metaDescription;
$page->content = $request->pageContent;
$page->status = $request->status;
$page->template = $request->template;
$page->module_handler = $module->handler;
$page->category_id = (int)$request->category > 0 ? $request->category : null;
// is any parent page specified?
if ($request->parentPage) {
$page->parent_id = $request->parentPage;
}
@@ -124,12 +150,12 @@ class CreateNewContent extends Controller
$page->title_photo = $file ? $file['filename'] : null;
// let template to modify request and content page
call_user_func_array([CurrentTemplate::handler(), 'beforeSave'], [&$page, $request]);
// save module-specific stuff
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
// save content of page before (possible) uploading related files
$page->save();
// upload files assigned to content page
@@ -35,6 +35,14 @@ class EditContent extends Controller
*/
private $file;
/**
* EditContent constructor.
*
* Load ContentHistory and File into this controller
*
* @param ContentHistory $history
* @param File $file
*/
public function __construct(ContentHistory $history, File $file)
{
$this->history = $history;
@@ -61,6 +69,11 @@ class EditContent extends Controller
$module = Module::where('handler', $page->module_handler)
->firstOrFail();
$pageHeading = trans('admin/contents.edit', ['name' => e($page->title)]);
if (is_callable([$module->handler, 'getCreateNewTitle'])) {
$pageHeading = call_user_func([$module->handler, 'getEditTitle'], $page);
}
// get all Blade templates for rendering page
$templates = Template::where('module_id', $module->id)
->select(['template_name', 'name', 'description'])
@@ -83,6 +96,7 @@ class EditContent extends Controller
// render view
return view('admin.content.edit', [
'pageHeading' => $pageHeading,
'contentStatuses' => $statuses,
'page' => $page,
'module' => $module,
+37 -5
View File
@@ -2,6 +2,7 @@
namespace Modules\Blog\Article\Handlers;
use App\Enumerations\ModulesHandlerToId;
use App\Handlers\Contracts\ContentTitles;
use App\Handlers\Handler;
use App\Http\Controllers\Admin\EditContent;
use App\Http\Controllers\Controller;
@@ -11,7 +12,7 @@ use App\Models\User;
use Illuminate\Support\Facades\Artisan;
use Modules\Blog\Article\Entities\Comment;
class Article extends Handler
class Article extends Handler implements ContentTitles
{
/**
* Render given module into visitor area.
@@ -89,10 +90,7 @@ class Article extends Handler
return $changedColumns;
}
public static function getOverviewTitle()
{
return trans('article::module.allArticles');
}
/**
*
@@ -139,4 +137,38 @@ class Article extends Handler
// seed action log types
// Artisan::call('')
}
/**
* Get translated title for pages overview of given type.
*
* This value is used for rendering list of all content pages of given type in administration.
*
* @return string
*/
public static function getOverviewTitle()
{
return trans('article::module.allArticles');
}
/**
* Title displayed above for for creating new content page
*
* @return string
*/
public static function getCreateNewTitle()
{
return trans('article::module.newArticle');
}
/**
* Title for form displayed for editin content page
*
* @param Content $content
*
* @return mixed
*/
public static function getEditTitle(Content $content)
{
return trans('article::module.editArticle');
}
}
@@ -2,5 +2,5 @@
return [
"allowComments" => "Povolit komentáře?",
"new" => "Napsat",
"overview" => "Všchny články",
"overview" => "Všechny články",
];
@@ -5,5 +5,7 @@ return [
"comments" => "Komentáře",
"commentsOverview" => "Všechny komentáře",
"description" => "Základní submodul pro blog. Tento modul umožňuje psát články.",
"editArticle" => "Upravuji článek",
"name" => "Články",
"newArticle" => "Napsat nový článek",
];
@@ -4,6 +4,8 @@ return [
'description' => 'Base submodule for blog',
'comments' => 'Comments',
'commentsOverview' => 'All comments',
'blog' => 'Blog',
'allArticles' => 'All articles',
'blog' => 'Blog'
'newArticle' => 'Write new article',
'editArticle' => 'Editing article'
];
+1 -1
View File
@@ -1,6 +1,6 @@
@extends('admin.layoutWithNavigation')
@section('pageHeading', @trans('admin/contents.edit', ['name' => e($page->title)]))
@section('pageHeading', $pageHeading)
@section('content')
+1 -1
View File
@@ -1,6 +1,6 @@
@extends('admin.layoutWithNavigation')
@section('pageHeading', @trans('admin/contents.new', ['name' => $moduleName]))
@section('pageHeading', trans($pageHeading))
@section('content')
@@ -1,5 +1,6 @@
<?php
return [
"cannotSetHomepageAsPartOfHomepage" => "No toto? Jak mám nastavit domovskou stárnku jako podstránku sama sebe?",
"invalidPageId" => "Nelze odebrat stránku z titulní strany, neboť uvedené ID neexistuje.",
"noPagesAvailable" => "Žádné stránky k dispozici.",
"noPagesSelected" => "Nebyla vybrána žádná stránka pro zobrazení na titulní straně. Zatím...",