Merge branch 'template_support' into dev

This commit is contained in:
Michal Kváček
2016-09-20 20:17:06 +02:00
148 changed files with 890 additions and 5299 deletions
@@ -14,6 +14,7 @@ use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Modules\Categories\Entities\Category;
use Pingpong\Modules\Facades\Module as ModuleInstance;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class CreateNewContent extends Controller
{
/**
@@ -87,6 +88,9 @@ class CreateNewContent extends Controller
public function postNew(CreateNewContentRequest $request, $moduleId)
{
$page = new Content();
$template = Module::where('is_template', true)
->where('enabled', true)
->first();
try {
$module = Module::findOrFail($moduleId);
} catch (NotFoundHttpException $e) {
@@ -120,6 +124,10 @@ class CreateNewContent extends Controller
$page->title_photo = $file ? $file['filename'] : null;
// let template to modify request and content page
call_user_func_array([$template->handler, 'beforeSave'], [&$page, $request]);
// save module-specific stuff
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
+21 -5
View File
@@ -56,23 +56,32 @@ class EditContent extends Controller
$page = Content::findOrFail($id);
$page->module_settings = json_decode($page->module_settings);
$allModules = ModulesHandlerToId::getWithTranslations();
$moduleId = $allModules[$page->module_handler];
$module = Module::findOrFail($moduleId);
// select template
$template = Module::where('is_template', true)
->where('enabled', true)
->first();
// get module ID
$module = Module::where('handler', $page->module_handler)->firstOrFail();
$templates = Template::where('module_id', $moduleId)
// get all Blade templates for rendering page
$templates = Template::where('module_id', $module->id)
->select(['template_name', 'name', 'description'])
->get();
// get module for Categories - PingPong module
$categoryModule = ModuleInstance::get('categories');
// add categories, if supported
$categories = [];
if ($module->support_categories && $categoryModule->enabled()) {
$categories = Category::where('module_id', $moduleId)
$categories = Category::where('module_id', $module->id)
->get();
}
// modify data for edit form according to installed template
call_user_func_array([$template->handler, 'beforePopulatingEditForm'], [&$page]);
$history = $this->history->getStructuredHistoryOf($page);
// render view
@@ -107,6 +116,10 @@ class EditContent extends Controller
* @var $page Content
*/
$page = Content::findOrFail($id);
$template = Module::where('is_template', true)
->where('enabled', true)
->first();
} catch (NotFoundHttpException $e) {
// log attempt of invalid edit
@@ -121,6 +134,9 @@ class EditContent extends Controller
// upload file - if provided
$file = $page->uploadTitlePhoto($request);
// let template to modify request and content page
call_user_func_array([$template->handler, 'beforeSave'], [&$page, $request]);
$request->url = Str::slug($request->url);
$request->parentPage = $request->parentPage ? $request->parentPage : null;
@@ -79,6 +79,13 @@ class EditWidget extends Controller
// create new widget
$widget = Widget::findOrFail($id);
// check if widget area is deletable
if (!$widget->deletable) {
return redirect()
->back()
->with('error', trans('admin/widgets.notDeletable'));
}
$widget->delete();
// redirect with success notification
@@ -3,7 +3,6 @@
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Http\Requests\EditWidgetAreaRequest;
use App\Models\WidgetArea;
use Illuminate\Database\Eloquent\ModelNotFoundException;
@@ -61,6 +60,13 @@ class EditWidgetArea extends Controller
return $this->invalidArea();
}
// check if widget area is deletable
if (!$area->deletable) {
return redirect()
->back()
->with('error', trans('admin/widgetAreas.notDeletableArea'));
}
// delete area
$area->delete();
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Visitor;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Models\Content;
use App\Models\Module;
use App\Models\Template;
use Illuminate\Support\Facades\Auth;
class ContentPage extends Controller
@@ -59,6 +61,11 @@ class ContentPage extends Controller
// get handler
$handler = new $page->module_handler;
$template = Module::where('is_template', true)->where('enabled', true)->first();
// do something template-specific
call_user_func_array([$template->handler, 'beforeRender'], [&$page]);
// render page
return $handler->render($page, '');
}