FEATURE: add blog module stub

This commit is contained in:
Michal Kváček
2016-08-15 20:49:12 +02:00
parent bd06797c24
commit ae1123ba39
33 changed files with 454 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
<?php
return [
'name' => 'Articles',
'translatedName' => 'article::module.name',
'translatedDescription' => 'article::module.description',
'alias' => 'blog-article',
'handler' => \Modules\Blog\Article\Handlers\Article::class,
'providers' => [\Modules\Blog\Article\Providers\ArticleServiceProvider::class],
'files' => ['start.php'],
'order' => 0,
];
+100
View File
@@ -0,0 +1,100 @@
<?php
namespace Modules\Blog\Article\Handlers;
use App\Enumerations\ModulesHandlerToId;
use App\Handlers\Handler;
use App\Http\Controllers\Controller;
use App\Http\Requests\Request;
use App\Models\Content;
use App\Models\User;
class Article extends Handler
{
/**
* Render given module into visitor area.
*
* @param Content $content DB model from table contents
* @param array $parameters parameters used for modifications/custom settings of given model
*
* @return mixed
*/
public function render(Content $content, $parameters)
{
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)
{
}
/**
* Save module-specific values into database
*
* @param Content $content
* @param Request $request
*
* @return mixed
* @internal param Widget $widget
*/
public static function createNew(Content &$content, Request $request)
{
}
/**
* Method used for editing existing content page.
*
* Reason why it is separated from createNew() method is simple - we need to save history of changes.
*
* @param Content $content
* @param Request $request
*
* @param $revisionID string ID of revision used
*
* @return int number of edited fields
*/
public static function edit(Content &$content, Request $request, $revisionID)
{
// TODO: Implement edit() method.
}
/**
*
* @param User $user
*/
public static function registerAdminMenu(User $user)
{
parent::registerAdminMenu($user);
$menu = \Menu::instance('mainMenu');
$menu->dropdown(trans('article::module.name'), function ($sub) {
$sub->route('article.new', trans('article::article.new'), [], 10, ['icon' => 'fa fa-fw fa-pencil']);
$sub->route('article.overview', trans('article::article.overview'), [], 30, ['icon' => 'fa fa-fw fa-book']);
}, 10, ['icon' => 'fa fa-fw fa-book']);
}
public static function getModuleId()
{
$handler = config('article.handler');
$allModules = ModulesHandlerToId::getWithTranslations();
$moduleId = isset($allModules[$handler]) ? $allModules[$handler] : null;
return $moduleId;
}
/**
* Install module
*
* @return mixed
*/
public static function install()
{
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
Route::group([
'middleware' => 'web',
'prefix' => 'article',
'namespace' => 'Modules\Blog\Article\Http\Controllers'
], function () {
Route::get('/', 'CategoriesOverview@getOverview')
->name('article.overview');
Route::get('/new', 'CreateNewCategory@getNew')
->name('article.new');
Route::post('/new', 'CreateNewCategory@postNew')
->name('article.postNew');
Route::get('/edit/{id}', 'EditCategory@getEdit')
->name('article.edit');
Route::post('/edit/{id}', 'EditCategory@postEdit')
->name('article.postEdit');
Route::get('/delete/{id}', 'EditCategory@delete')
->name('article.delete');
});
@@ -0,0 +1,94 @@
<?php namespace Modules\Blog\Article\Providers;
use Illuminate\Support\ServiceProvider;
use Pingpong\Modules\Facades\Module;
class ArticleServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
}
/**
* Register config.
*
* @return void
*/
protected function registerConfig()
{
$this->publishes([
__DIR__.'/../Config/config.php' => config_path('article.php'),
]);
$this->mergeConfigFrom(
__DIR__.'/../Config/config.php', 'article'
);
}
/**
* Register views.
*
* @return void
*/
public function registerViews()
{
$viewPath = base_path('resources/views/modules/article');
$sourcePath = __DIR__.'/../Resources/views';
$this->publishes([$sourcePath => $viewPath]);
$this->loadViewsFrom(array_merge(array_map(function ($path) {
return $path . '/modules/article';
}, \Config::get('view.paths')), [$sourcePath]), 'article');
}
/**
* Register translations.
*
* @return void
*/
public function registerTranslations()
{
$langPath = base_path('resources/lang/modules/article');
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, 'article');
} else {
$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'article');
}
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}
}
@@ -0,0 +1,4 @@
<?php
return [
];
@@ -0,0 +1,5 @@
<?php
return [
'name' => 'Article',
'description' => 'Base submodule for blog'
];
+15
View File
@@ -0,0 +1,15 @@
{
"name": "pingpong-modules/article",
"description": "",
"authors": [
{
"name": "Pingpong Labs",
"email": "pingpong.labs@gmail.com"
}
],
"autoload": {
"psr-4": {
"Modules\\Article\\": ""
}
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
/*
|--------------------------------------------------------------------------
| Register Namespaces And Routes
|--------------------------------------------------------------------------
|
| When a module starting, this file will executed automatically. This helps
| to register some namespaces like translator or view. Also this file
| will load the routes file for each module. You may also modify
| this file as you want.
|
*/
require __DIR__ . '/Http/routes.php';