FEATURE #1753: remove pingpong/modules and use custom solution
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Registrators;
|
||||
|
||||
use App\CMS\Enumerations\Exceptions\EnumerationExistsException;
|
||||
use App\CMS\Exceptions\Enumerations\EnumerationExistsException;
|
||||
use App\CMS\Handlers\Contracts\SearchHandler;
|
||||
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
||||
use App\CMS\Handlers\Registrators\Items\SearchEngine;
|
||||
|
||||
@@ -22,16 +22,9 @@ class CurrentTemplate implements TemplateHandler
|
||||
{
|
||||
if (!self::$initialized) {
|
||||
self::$template = Cache::rememberForever('current-template', function () {
|
||||
$template = Module::where('is_template', true)
|
||||
return Module::where('is_template', true)
|
||||
->where('enabled', true)
|
||||
->first();
|
||||
|
||||
// todo remove after adding $casts into Module model
|
||||
if ($template) {
|
||||
$template->module_settings = json_decode($template->module_settings);
|
||||
}
|
||||
|
||||
return $template;
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\CMS\Modules\ServiceProviders;
|
||||
|
||||
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
||||
|
||||
abstract class ServiceProvider extends LaravelServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
protected $alias = false;
|
||||
protected $path = false;
|
||||
|
||||
abstract protected function setModuleAlias();
|
||||
|
||||
abstract protected function setModulePath();
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->setModuleAlias();
|
||||
$this->setModulePath();
|
||||
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConfig()
|
||||
{
|
||||
$this->publishes([$this->path . '/../Config/config.php' => config_path($this->alias . '.php')]);
|
||||
$this->mergeConfigFrom($this->path . '/../Config/config.php', $this->alias);
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
* @return void
|
||||
*/
|
||||
protected function registerViews()
|
||||
{
|
||||
$viewPath = base_path('resources/views/modules/' . $this->alias);
|
||||
$sourcePath = $this->path . '/../Resources/views';
|
||||
|
||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||
return $path . '/modules/' . $this->alias;
|
||||
}, \Config::get('view.paths')), [$sourcePath]), $this->alias);
|
||||
|
||||
if (is_dir($sourcePath)) {
|
||||
$this->publishes([$sourcePath => $viewPath], 'module-views');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
* @return void
|
||||
*/
|
||||
protected function registerTranslations()
|
||||
{
|
||||
$this->loadTranslationsFrom($this->path . '/../Resources/lang', $this->alias);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '$Module$',
|
||||
'translatedName' => '$module$::$module$.name',
|
||||
'translatedDescription' => '$module$::$module$.description',
|
||||
'alias' => 'categories',
|
||||
'handler' => \Modules\$Module$\Handlers\$Module$Handler::class,
|
||||
'providers' => [\Modules\$Module$\Providers\$Module$ServiceProvider::class],
|
||||
'files' => ['Http/routes.php'],
|
||||
'order' => 0,
|
||||
];
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Modules\$ModuleNamespace$\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class $Entity$ extends Model {
|
||||
// ...
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\$ModuleNamespace$\Handlers;
|
||||
|
||||
use App\CMS\Contracts\Content\ContentTitles;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
class $Module$ContentHandler extends $Module$Handler implements 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()
|
||||
{
|
||||
// TODO: Implement getOverviewTitle() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Title displayed above for for creating new content page
|
||||
* @return string
|
||||
*/
|
||||
public static function getCreateNewTitle()
|
||||
{
|
||||
// TODO: Implement getCreateNewTitle() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Title for form displayed for editin content page
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getEditTitle(Content $content)
|
||||
{
|
||||
// TODO: Implement getEditTitle() method.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\$ModuleNamespace$\Handlers;
|
||||
|
||||
use App\CMS\Handlers\Handler;
|
||||
use App\Models\User;
|
||||
|
||||
class $Module$Handler extends Handler
|
||||
{
|
||||
/**
|
||||
* Register admin menu
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public static function registerAdminMenu(User $user)
|
||||
{
|
||||
// register links in admin menu
|
||||
$menu = \Menu::instance('mainMenu');
|
||||
|
||||
$menu->dropdown(trans('$module$::$module$.name'), function ($submenu) use ($user) {
|
||||
$submenu->route('$module$.overview', trans('$module$::$module$.overview'), [], 20, ['icon' => 'fa fa-fw fa-list']);
|
||||
$submenu->route('$module$.new', trans('$module$::$module$.new'), [], 21, ['icon' => 'fa fa-fw fa-plus']);
|
||||
}, 15, ['icon' => 'fa fa-fw']);
|
||||
|
||||
|
||||
|
||||
// TODO: add admin menu entries
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this module support categories?
|
||||
* @return boolean
|
||||
*/
|
||||
public static function supportCategories()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\$ModuleNamespace$\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use Modules\$ModuleNamespace$\Http\Requests\Update$Entity$;
|
||||
use Modules\$ModuleNamespace$\Http\Requests\Create$Entity$;
|
||||
use Modules\$ModuleNamespace$\Repositories\$Module$Repository;
|
||||
use $EntityNamespace$\$Entity$ as $Entity$Entity;
|
||||
|
||||
class $Module$ extends Controller
|
||||
{
|
||||
/**
|
||||
* @var $Module$Repository
|
||||
*/
|
||||
private $$module$Repository;
|
||||
|
||||
public function __construct($Module$Repository $$module$Repository)
|
||||
{
|
||||
$this->$module$Repository = $$module$Repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$items = $Entity$Entity::all();
|
||||
|
||||
return view('$module$::admin/index', compact('items'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for updating entity
|
||||
*
|
||||
* @param $Entity$Entity $entity
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($Entity$Entity $entity)
|
||||
{
|
||||
return view('$module$::admin/update', compact('entity'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update existing entity
|
||||
*
|
||||
* @param Update$Entity$ $request
|
||||
* @param $Entity$Entity $item
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Update$Entity$ $request, $Entity$Entity $entity)
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
$this->$module$Repository->update($entity, $request->all());
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans('$module$.$module.successfullyUpdated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for creating new entity
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function create() {
|
||||
$entity = new $Entity$Entity();
|
||||
|
||||
return view('$module$::admin/create', compact('entity'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new instance of entity
|
||||
*/
|
||||
public function store(Create$Entity$ $request) {
|
||||
// ...
|
||||
|
||||
$this->$module$Repository->create($request->all());
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans('$module$.$module.successfullyUpdated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete entity
|
||||
*
|
||||
* @param $Entity$ $entity
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($Entity$ $entity) {
|
||||
$entity->delete();
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans('$module$.$module.successfullyDeleted'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Modules\$ModuleNamespace$\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class Create$Entity$ extends Request {
|
||||
public function rules()
|
||||
{
|
||||
return parent::rules();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Modules\$ModuleNamespace$\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class Update$Entity$ extends Request {
|
||||
public function rules()
|
||||
{
|
||||
return parent::rules();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
\Route::group([
|
||||
'prefix' => \LaravelLocalization::setLocale() . '/admin/$module$',
|
||||
'middleware' => ['admin'],
|
||||
'namespace' => 'Modules\$Module$\Http\Controllers\Admin'
|
||||
], function () {
|
||||
Route::get('/', '$Module$@index')
|
||||
->name('$module$.overview');
|
||||
|
||||
Route::get('/new', '$Module$@create')
|
||||
->name('$module$.new');
|
||||
|
||||
Route::post('/new', '$Module$@store')
|
||||
->name('$module$.postNew');
|
||||
|
||||
Route::get('/edit/{id}', '$Module$@edit')
|
||||
->name('$module$.edit');
|
||||
|
||||
Route::post('/edit/{id}', '$Module$@update')
|
||||
->name('$module$.postEdit');
|
||||
|
||||
Route::get('/delete/{id}', '$Module$@delete')
|
||||
->name('$module$.delete');
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\$Module$\Providers;
|
||||
|
||||
use App\CMS\Contracts\Modules\ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class $Module$ServiceProvider
|
||||
*
|
||||
* Service provider for module $Module$
|
||||
*
|
||||
* @package Modules\$Module$\Providers
|
||||
*/
|
||||
class $Module$ServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Set module Alias
|
||||
*/
|
||||
protected function setModuleAlias()
|
||||
{
|
||||
$this->alias = strtolower('$module$');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set path to module
|
||||
*/
|
||||
protected function setModulePath()
|
||||
{
|
||||
$this->path = __DIR__;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Modules\$ModuleNamespace$\Repositories;
|
||||
|
||||
use $EntityNamespace$\$Entity$ as $Entity$Entity;
|
||||
|
||||
class $Module$Repository {
|
||||
/**
|
||||
* Create new instance of entity
|
||||
*
|
||||
* @param $data
|
||||
*/
|
||||
public function create($data) {
|
||||
$Entity$Entity::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update entity
|
||||
*
|
||||
* @param $Entity$Entity $entity
|
||||
*/
|
||||
public function update($Entity$Entity $entity, $data) {
|
||||
$entity->update($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '$Module$',
|
||||
'new' => 'Vytvořit nový',
|
||||
'description' => '',
|
||||
'successfullyUpdated' => 'Úspěšně upraveno.',
|
||||
'successfullyCreated' => 'Úspěšně vytvořeno.',
|
||||
'successfullyDeleted' => 'Úspěšně smazáno.',
|
||||
'overview' => 'Přehled',
|
||||
'noItems' => 'Žádná data.',
|
||||
'save' => 'Uložit'
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('$module$::$module$.name'))
|
||||
|
||||
@section('content')
|
||||
@include('$module$::admin/form', ['action' => route('$module$.new')])
|
||||
@endsection
|
||||
@@ -0,0 +1,7 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('$module$::$module$.name'))
|
||||
|
||||
@section('content')
|
||||
@include('$module$::admin/form', ['action' => route('$module$.update')])
|
||||
@endsection
|
||||
@@ -0,0 +1,6 @@
|
||||
<form action="{{$action}}" method="post">
|
||||
|
||||
{{--...--}}
|
||||
|
||||
<input type="submit" class="btn btn-primary" value="@lang('$module$::$module$.save')">
|
||||
</form>
|
||||
@@ -0,0 +1,17 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('$module$::$module$.overview'))
|
||||
|
||||
@section('content')
|
||||
@if (!empty($items))
|
||||
<table>
|
||||
@foreach($items as $item)
|
||||
|
||||
@endforeach
|
||||
</table>
|
||||
@else
|
||||
<div class="alert alert-info">
|
||||
<em>@trans('$module$::$module$.noItems')</em>
|
||||
</div>
|
||||
@endif
|
||||
@endsection
|
||||
Reference in New Issue
Block a user