From ae1123ba398628c75e2cd92f8a87511544ca6b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Mon, 15 Aug 2016 20:49:12 +0200 Subject: [PATCH 1/9] FEATURE: add blog module stub --- modules/Blog/Article/Config/config.php | 12 +++ modules/Blog/Article/Handlers/Article.php | 100 ++++++++++++++++++ .../Blog/Article/Http/Controllers/.gitkeep | 0 modules/Blog/Article/Http/routes.php | 25 +++++ .../Providers/ArticleServiceProvider.php | 94 ++++++++++++++++ .../Article/Resources/lang/en/article.php | 4 + .../Blog/Article/Resources/lang/en/module.php | 5 + modules/Blog/Article/Resources/views/.gitkeep | 0 modules/Blog/Article/composer.json | 15 +++ modules/Blog/Article/start.php | 15 +++ modules/Blog/ArticleList/Assets/.gitkeep | 0 modules/Blog/ArticleList/Config/.gitkeep | 0 modules/Blog/ArticleList/Config/config.php | 5 + modules/Blog/ArticleList/Console/.gitkeep | 0 .../ArticleList/Database/Migrations/.gitkeep | 0 .../ArticleList/Database/Seeders/.gitkeep | 0 .../Seeders/ArticleListDatabaseSeeder.php | 20 ++++ modules/Blog/ArticleList/Entities/.gitkeep | 0 .../ArticleList/Http/Controllers/.gitkeep | 0 .../Controllers/ArticleListController.php | 12 +++ .../Blog/ArticleList/Http/Middleware/.gitkeep | 0 .../Blog/ArticleList/Http/Requests/.gitkeep | 0 modules/Blog/ArticleList/Http/routes.php | 6 ++ modules/Blog/ArticleList/Providers/.gitkeep | 0 .../Providers/ArticleListServiceProvider.php | 97 +++++++++++++++++ .../Blog/ArticleList/Repositories/.gitkeep | 0 .../Blog/ArticleList/Resources/lang/.gitkeep | 0 .../Blog/ArticleList/Resources/views/.gitkeep | 0 .../Resources/views/index.blade.php | 11 ++ .../Resources/views/layouts/master.blade.php | 12 +++ modules/Blog/ArticleList/Tests/.gitkeep | 0 modules/Blog/ArticleList/start.php | 15 +++ modules/Blog/info.php | 6 ++ 33 files changed, 454 insertions(+) create mode 100644 modules/Blog/Article/Config/config.php create mode 100644 modules/Blog/Article/Handlers/Article.php create mode 100644 modules/Blog/Article/Http/Controllers/.gitkeep create mode 100644 modules/Blog/Article/Http/routes.php create mode 100644 modules/Blog/Article/Providers/ArticleServiceProvider.php create mode 100644 modules/Blog/Article/Resources/lang/en/article.php create mode 100644 modules/Blog/Article/Resources/lang/en/module.php create mode 100644 modules/Blog/Article/Resources/views/.gitkeep create mode 100644 modules/Blog/Article/composer.json create mode 100644 modules/Blog/Article/start.php create mode 100644 modules/Blog/ArticleList/Assets/.gitkeep create mode 100644 modules/Blog/ArticleList/Config/.gitkeep create mode 100644 modules/Blog/ArticleList/Config/config.php create mode 100644 modules/Blog/ArticleList/Console/.gitkeep create mode 100644 modules/Blog/ArticleList/Database/Migrations/.gitkeep create mode 100644 modules/Blog/ArticleList/Database/Seeders/.gitkeep create mode 100644 modules/Blog/ArticleList/Database/Seeders/ArticleListDatabaseSeeder.php create mode 100644 modules/Blog/ArticleList/Entities/.gitkeep create mode 100644 modules/Blog/ArticleList/Http/Controllers/.gitkeep create mode 100644 modules/Blog/ArticleList/Http/Controllers/ArticleListController.php create mode 100644 modules/Blog/ArticleList/Http/Middleware/.gitkeep create mode 100644 modules/Blog/ArticleList/Http/Requests/.gitkeep create mode 100644 modules/Blog/ArticleList/Http/routes.php create mode 100644 modules/Blog/ArticleList/Providers/.gitkeep create mode 100644 modules/Blog/ArticleList/Providers/ArticleListServiceProvider.php create mode 100644 modules/Blog/ArticleList/Repositories/.gitkeep create mode 100644 modules/Blog/ArticleList/Resources/lang/.gitkeep create mode 100644 modules/Blog/ArticleList/Resources/views/.gitkeep create mode 100644 modules/Blog/ArticleList/Resources/views/index.blade.php create mode 100644 modules/Blog/ArticleList/Resources/views/layouts/master.blade.php create mode 100644 modules/Blog/ArticleList/Tests/.gitkeep create mode 100644 modules/Blog/ArticleList/start.php create mode 100644 modules/Blog/info.php diff --git a/modules/Blog/Article/Config/config.php b/modules/Blog/Article/Config/config.php new file mode 100644 index 00000000..f509e809 --- /dev/null +++ b/modules/Blog/Article/Config/config.php @@ -0,0 +1,12 @@ + '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, +]; \ No newline at end of file diff --git a/modules/Blog/Article/Handlers/Article.php b/modules/Blog/Article/Handlers/Article.php new file mode 100644 index 00000000..aa8ec0c8 --- /dev/null +++ b/modules/Blog/Article/Handlers/Article.php @@ -0,0 +1,100 @@ +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() + { + } +} \ No newline at end of file diff --git a/modules/Blog/Article/Http/Controllers/.gitkeep b/modules/Blog/Article/Http/Controllers/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/Article/Http/routes.php b/modules/Blog/Article/Http/routes.php new file mode 100644 index 00000000..b9ad36f4 --- /dev/null +++ b/modules/Blog/Article/Http/routes.php @@ -0,0 +1,25 @@ + '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'); +}); \ No newline at end of file diff --git a/modules/Blog/Article/Providers/ArticleServiceProvider.php b/modules/Blog/Article/Providers/ArticleServiceProvider.php new file mode 100644 index 00000000..888c0ed8 --- /dev/null +++ b/modules/Blog/Article/Providers/ArticleServiceProvider.php @@ -0,0 +1,94 @@ +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(); + } + +} diff --git a/modules/Blog/Article/Resources/lang/en/article.php b/modules/Blog/Article/Resources/lang/en/article.php new file mode 100644 index 00000000..05e0b10e --- /dev/null +++ b/modules/Blog/Article/Resources/lang/en/article.php @@ -0,0 +1,4 @@ + 'Article', + 'description' => 'Base submodule for blog' +]; \ No newline at end of file diff --git a/modules/Blog/Article/Resources/views/.gitkeep b/modules/Blog/Article/Resources/views/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/Article/composer.json b/modules/Blog/Article/composer.json new file mode 100644 index 00000000..a7baacdf --- /dev/null +++ b/modules/Blog/Article/composer.json @@ -0,0 +1,15 @@ +{ + "name": "pingpong-modules/article", + "description": "", + "authors": [ + { + "name": "Pingpong Labs", + "email": "pingpong.labs@gmail.com" + } + ], + "autoload": { + "psr-4": { + "Modules\\Article\\": "" + } + } +} \ No newline at end of file diff --git a/modules/Blog/Article/start.php b/modules/Blog/Article/start.php new file mode 100644 index 00000000..7be329cb --- /dev/null +++ b/modules/Blog/Article/start.php @@ -0,0 +1,15 @@ + 'ArticleList' +]; \ No newline at end of file diff --git a/modules/Blog/ArticleList/Console/.gitkeep b/modules/Blog/ArticleList/Console/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/Database/Migrations/.gitkeep b/modules/Blog/ArticleList/Database/Migrations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/Database/Seeders/.gitkeep b/modules/Blog/ArticleList/Database/Seeders/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/Database/Seeders/ArticleListDatabaseSeeder.php b/modules/Blog/ArticleList/Database/Seeders/ArticleListDatabaseSeeder.php new file mode 100644 index 00000000..5daa172d --- /dev/null +++ b/modules/Blog/ArticleList/Database/Seeders/ArticleListDatabaseSeeder.php @@ -0,0 +1,20 @@ +call("OthersTableSeeder"); + } + +} \ No newline at end of file diff --git a/modules/Blog/ArticleList/Entities/.gitkeep b/modules/Blog/ArticleList/Entities/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/Http/Controllers/.gitkeep b/modules/Blog/ArticleList/Http/Controllers/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/Http/Controllers/ArticleListController.php b/modules/Blog/ArticleList/Http/Controllers/ArticleListController.php new file mode 100644 index 00000000..df742323 --- /dev/null +++ b/modules/Blog/ArticleList/Http/Controllers/ArticleListController.php @@ -0,0 +1,12 @@ + 'web', 'prefix' => 'articlelist', 'namespace' => 'Modules\Blog\ArticleList\Http\Controllers'], function() +{ + Route::get('/', 'ArticleListController@index'); +}); \ No newline at end of file diff --git a/modules/Blog/ArticleList/Providers/.gitkeep b/modules/Blog/ArticleList/Providers/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/Providers/ArticleListServiceProvider.php b/modules/Blog/ArticleList/Providers/ArticleListServiceProvider.php new file mode 100644 index 00000000..510a581e --- /dev/null +++ b/modules/Blog/ArticleList/Providers/ArticleListServiceProvider.php @@ -0,0 +1,97 @@ +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('articlelist.php'), + ]); + $this->mergeConfigFrom( + __DIR__.'/../Config/config.php', 'articlelist' + ); + } + + /** + * Register views. + * + * @return void + */ + public function registerViews() + { + $viewPath = base_path('resources/views/modules/articlelist'); + + $sourcePath = __DIR__.'/../Resources/views'; + + $this->publishes([ + $sourcePath => $viewPath + ]); + + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/articlelist'; + }, \Config::get('view.paths')), [$sourcePath]), 'articlelist'); + } + + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $langPath = base_path('resources/lang/modules/articlelist'); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, 'articlelist'); + } else { + $this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'articlelist'); + } + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array(); + } + +} diff --git a/modules/Blog/ArticleList/Repositories/.gitkeep b/modules/Blog/ArticleList/Repositories/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/Resources/lang/.gitkeep b/modules/Blog/ArticleList/Resources/lang/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/Resources/views/.gitkeep b/modules/Blog/ArticleList/Resources/views/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/Resources/views/index.blade.php b/modules/Blog/ArticleList/Resources/views/index.blade.php new file mode 100644 index 00000000..bbb855f0 --- /dev/null +++ b/modules/Blog/ArticleList/Resources/views/index.blade.php @@ -0,0 +1,11 @@ +@extends('articlelist::layouts.master') + +@section('content') + +

Hello World

+ +

+ This view is loaded from module: {!! config('articlelist.name') !!} +

+ +@stop \ No newline at end of file diff --git a/modules/Blog/ArticleList/Resources/views/layouts/master.blade.php b/modules/Blog/ArticleList/Resources/views/layouts/master.blade.php new file mode 100644 index 00000000..0519dc92 --- /dev/null +++ b/modules/Blog/ArticleList/Resources/views/layouts/master.blade.php @@ -0,0 +1,12 @@ + + + + + + + Module ArticleList + + + @yield('content') + + \ No newline at end of file diff --git a/modules/Blog/ArticleList/Tests/.gitkeep b/modules/Blog/ArticleList/Tests/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/ArticleList/start.php b/modules/Blog/ArticleList/start.php new file mode 100644 index 00000000..7be329cb --- /dev/null +++ b/modules/Blog/ArticleList/start.php @@ -0,0 +1,15 @@ + 'Blog', + 'description' => '', + 'hasSubmodules' => true, +]; \ No newline at end of file From 206e5201b80ab2950a741fbb49eb60e1a70af80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Mon, 15 Aug 2016 22:24:23 +0200 Subject: [PATCH 2/9] FIX: reset namespace and module ID after each registered path --- app/Handlers/Registrators/TemplateRegistrator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Handlers/Registrators/TemplateRegistrator.php b/app/Handlers/Registrators/TemplateRegistrator.php index 0a7f5480..6788df67 100644 --- a/app/Handlers/Registrators/TemplateRegistrator.php +++ b/app/Handlers/Registrators/TemplateRegistrator.php @@ -73,6 +73,7 @@ class TemplateRegistrator public function unsetNamespace() { $this->namespace = null; + $this->setModuleId(null); } /** @@ -95,6 +96,8 @@ class TemplateRegistrator // register path $this->registerPath($this->registeredPath, $name); + + $this->unsetNamespace(); } /** @@ -194,6 +197,8 @@ class TemplateRegistrator 'editable' => 1 ]; + echo 'ukladam do db '.$templateName."\n"; + // save template into database $newTemplate = Template::create($params); From cd369c327fb29e4df6668ec2d3421c2a3ff2b2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Mon, 15 Aug 2016 23:16:06 +0200 Subject: [PATCH 3/9] FEATURE: add templates to blog/article --- .../Providers/ArticleServiceProvider.php | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/modules/Blog/Article/Providers/ArticleServiceProvider.php b/modules/Blog/Article/Providers/ArticleServiceProvider.php index 888c0ed8..0d52f03c 100644 --- a/modules/Blog/Article/Providers/ArticleServiceProvider.php +++ b/modules/Blog/Article/Providers/ArticleServiceProvider.php @@ -1,6 +1,9 @@ publishes([ - __DIR__.'/../Config/config.php' => config_path('article.php'), - ]); - $this->mergeConfigFrom( - __DIR__.'/../Config/config.php', 'article' - ); + $this->publishes([__DIR__.'/../Config/config.php' => config_path('article.php')]); + $this->mergeConfigFrom(__DIR__.'/../Config/config.php', 'article'); } /** @@ -63,6 +62,22 @@ class ArticleServiceProvider extends ServiceProvider { $this->loadViewsFrom(array_merge(array_map(function ($path) { return $path . '/modules/article'; }, \Config::get('view.paths')), [$sourcePath]), 'article'); + + /** + * @var $registrator TemplateRegistrator + */ + try { + // setup some global variables + $registrator = $this->app->make('registerTemplateDir'); + $registrator->setBaseDirectory('resources/views/modules/article/visitor'); + $registrator->setNamespace('article'); + $registrator->setModuleId(Article::getModuleId()); + + // register path with current template name + $registrator->register(config('app.theme'), 'article::admin/adminMenu.templatePath'); + } catch (InvalidArgumentException $e) { + // ignore this exception + } } /** From 8edde44c0d2ea80df6851859ba594abe2dd5e741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Tue, 16 Aug 2016 00:50:00 +0200 Subject: [PATCH 4/9] FIX: fix saving new content without category --- app/Http/Controllers/Admin/CreateNewContent.php | 2 +- modules/Blog/Article/Resources/views/.gitkeep | 0 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 modules/Blog/Article/Resources/views/.gitkeep diff --git a/app/Http/Controllers/Admin/CreateNewContent.php b/app/Http/Controllers/Admin/CreateNewContent.php index cf71a7e8..1beee33b 100644 --- a/app/Http/Controllers/Admin/CreateNewContent.php +++ b/app/Http/Controllers/Admin/CreateNewContent.php @@ -109,7 +109,7 @@ class CreateNewContent extends Controller $page->status = $request->status; $page->template = $request->template; $page->module_handler = $module->handler; - $page->category_id = $request->category; + $page->category_id = (int)$request->category > 0 ? $request->category : null; if ($request->parentPage) { $page->parent_id = $request->parentPage; diff --git a/modules/Blog/Article/Resources/views/.gitkeep b/modules/Blog/Article/Resources/views/.gitkeep deleted file mode 100644 index e69de29b..00000000 From af3db57b29c53c6239b7b02d069702e28286311b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Tue, 16 Aug 2016 00:50:37 +0200 Subject: [PATCH 5/9] FEATURE: add translation for history.columnCategory --- resources/lang/cs/admin/history.php | 45 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/resources/lang/cs/admin/history.php b/resources/lang/cs/admin/history.php index a82b3831..f263f9ba 100644 --- a/resources/lang/cs/admin/history.php +++ b/resources/lang/cs/admin/history.php @@ -1,25 +1,26 @@ "Zpět na editaci obsahu", -"backToOverview" => "Zpět na přehled historie", -"changedFromTo" => "Změna z :from na :to", -"columnFile" => "Přiřazené soubory", -"columnIs_homepage" => "Domovská stránka", -"columnMetaDescription" => "Popis", -"columnMetaKeywords" => "Klíčová slova", -"columnPageContent" => "Obsah stránky", -"columnParentPage" => "Nadřazená stránka", -"columnStatus" => "Viditelnost stránky", -"columnTemplate" => "Šablona", -"columnTitle" => "Titulek", -"columnTitlePhotoFilename" => "Titulní obrázek", -"columnUrl" => "URL", -"deletedFile" => "Odebrán soubor :file.", -"diff" => "Rozdíl", -"diffPageName" => "Rozdíl v :column", -"emptyValue" => "nic", -"numOfChanges" => "Jedna změna|:count změny|:count změn", -"pageName" => "Historie :name", -"setupAsHomepage" => "Nastaveno jako domovská stránka", -"uploadedFile" => "Nahrán soubor :file.", + "backToEdit" => "Zpět na editaci obsahu", + "backToOverview" => "Zpět na přehled historie", + "changedFromTo" => "Změna z :from na :to", + "columnCategory" => "Kategorie", + "columnFile" => "Přiřazené soubory", + "columnIs_homepage" => "Domovská stránka", + "columnMetaDescription" => "Popis", + "columnMetaKeywords" => "Klíčová slova", + "columnPageContent" => "Obsah stránky", + "columnParentPage" => "Nadřazená stránka", + "columnStatus" => "Viditelnost stránky", + "columnTemplate" => "Šablona", + "columnTitle" => "Titulek", + "columnTitlePhotoFilename" => "Titulní obrázek", + "columnUrl" => "URL", + "deletedFile" => "Odebrán soubor :file.", + "diff" => "Rozdíl", + "diffPageName" => "Rozdíl v :column", + "emptyValue" => "nic", + "numOfChanges" => "Jedna změna|:count změny|:count změn", + "pageName" => "Historie :name", + "setupAsHomepage" => "Nastaveno jako domovská stránka", + "uploadedFile" => "Nahrán soubor :file.", ]; From debe80a314e1f34b67fe2fbf43476df72bdbf066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Tue, 16 Aug 2016 00:51:17 +0200 Subject: [PATCH 6/9] FEATURE: implement loadExtraData as empty function in Handler --- app/Handlers/Handler.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Handlers/Handler.php b/app/Handlers/Handler.php index 11d0b742..63ddab59 100644 --- a/app/Handlers/Handler.php +++ b/app/Handlers/Handler.php @@ -56,6 +56,10 @@ abstract class Handler extends BaseHandler implements AppHandler // temporarily nothing to do } + public static function loadExtraData(Content $content) { + // temporarily nothing to do + } + public static function getExtendedFormInputsEdit() { return self::getExtendedFormInputsCreate(); From 6f799f00bbcb561da152eb56508cfc1db369e8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Tue, 16 Aug 2016 00:52:09 +0200 Subject: [PATCH 7/9] FEATURE: add support for writing blog posts --- modules/Blog/Article/Handlers/Article.php | 33 +++++-- .../Article/Resources/lang/en/article.php | 4 +- .../views/admin/content/basicInfo.blade.php | 89 +++++++++++++++++++ 3 files changed, 116 insertions(+), 10 deletions(-) create mode 100644 modules/Blog/Article/Resources/views/admin/content/basicInfo.blade.php diff --git a/modules/Blog/Article/Handlers/Article.php b/modules/Blog/Article/Handlers/Article.php index aa8ec0c8..fb4aeb83 100644 --- a/modules/Blog/Article/Handlers/Article.php +++ b/modules/Blog/Article/Handlers/Article.php @@ -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; } /** diff --git a/modules/Blog/Article/Resources/lang/en/article.php b/modules/Blog/Article/Resources/lang/en/article.php index 05e0b10e..2d1e8b44 100644 --- a/modules/Blog/Article/Resources/lang/en/article.php +++ b/modules/Blog/Article/Resources/lang/en/article.php @@ -1,4 +1,6 @@ 'Allow comments?', + 'new' => 'Write new', + 'overview' => 'All articles' ]; \ No newline at end of file diff --git a/modules/Blog/Article/Resources/views/admin/content/basicInfo.blade.php b/modules/Blog/Article/Resources/views/admin/content/basicInfo.blade.php new file mode 100644 index 00000000..e150c58f --- /dev/null +++ b/modules/Blog/Article/Resources/views/admin/content/basicInfo.blade.php @@ -0,0 +1,89 @@ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + @if (isset($errors) && $errors->has('status')) +
+ {{ $errors->first('status') }} +
+ @endif +
+
+ +
+ + @if($module->support_categories && count($categories)) +
+ +
+ + @endif +
+ +
+
+ +
+
\ No newline at end of file From be81834aad51979021ef97de6c4c32e45d5e83e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Tue, 16 Aug 2016 13:20:07 +0200 Subject: [PATCH 8/9] FEATURE: add stub of module for comments --- modules/Blog/Comments/Config/config.php | 12 +++ modules/Blog/Comments/Entities/.gitkeep | 0 modules/Blog/Comments/Handlers/Comments.php | 37 ++++++++ .../Controllers/ArticleListController.php | 12 +++ modules/Blog/Comments/Http/routes.php | 6 ++ .../Providers/CommentsServiceProvider.php | 89 +++++++++++++++++++ .../Comments/Resources/lang/en/module.php | 6 ++ modules/Blog/Comments/start.php | 15 ++++ 8 files changed, 177 insertions(+) create mode 100644 modules/Blog/Comments/Config/config.php create mode 100644 modules/Blog/Comments/Entities/.gitkeep create mode 100644 modules/Blog/Comments/Handlers/Comments.php create mode 100644 modules/Blog/Comments/Http/Controllers/ArticleListController.php create mode 100644 modules/Blog/Comments/Http/routes.php create mode 100644 modules/Blog/Comments/Providers/CommentsServiceProvider.php create mode 100644 modules/Blog/Comments/Resources/lang/en/module.php create mode 100644 modules/Blog/Comments/start.php diff --git a/modules/Blog/Comments/Config/config.php b/modules/Blog/Comments/Config/config.php new file mode 100644 index 00000000..248333ab --- /dev/null +++ b/modules/Blog/Comments/Config/config.php @@ -0,0 +1,12 @@ + 'Comments', + 'translatedName' => 'comments::module.name', + 'translatedDescription' => 'comments::module.description', + 'alias' => 'blog-comments', + 'handler' => \Modules\Blog\Comments\Handlers\Comments::class, + 'providers' => [\Modules\Blog\Comments\Providers\CommentsServiceProvider::class], + 'files' => ['start.php'], + 'order' => 0, +]; \ No newline at end of file diff --git a/modules/Blog/Comments/Entities/.gitkeep b/modules/Blog/Comments/Entities/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/Blog/Comments/Handlers/Comments.php b/modules/Blog/Comments/Handlers/Comments.php new file mode 100644 index 00000000..b2674d0d --- /dev/null +++ b/modules/Blog/Comments/Handlers/Comments.php @@ -0,0 +1,37 @@ +dropdown(trans('comments::module.name'), function ($sub) { + $sub->route('comments.overview', trans('comments::module.overview'), [], 10, ['icon' => 'fa fa-fw fa-commenting-o']); + }, 10, ['icon' => 'fa fa-fw fa-comments-o']); + } +} \ No newline at end of file diff --git a/modules/Blog/Comments/Http/Controllers/ArticleListController.php b/modules/Blog/Comments/Http/Controllers/ArticleListController.php new file mode 100644 index 00000000..33ad274f --- /dev/null +++ b/modules/Blog/Comments/Http/Controllers/ArticleListController.php @@ -0,0 +1,12 @@ + 'web', 'prefix' => 'comments', 'namespace' => 'Modules\Blog\Comments\Http\Controllers'], function() +{ + Route::get('/', 'CommentsController@index')->name('comments.overview'); +}); \ No newline at end of file diff --git a/modules/Blog/Comments/Providers/CommentsServiceProvider.php b/modules/Blog/Comments/Providers/CommentsServiceProvider.php new file mode 100644 index 00000000..adb026f2 --- /dev/null +++ b/modules/Blog/Comments/Providers/CommentsServiceProvider.php @@ -0,0 +1,89 @@ +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('comments.php')]); + $this->mergeConfigFrom(__DIR__.'/../Config/config.php', 'comments'); + } + + /** + * Register views. + * + * @return void + */ + public function registerViews() + { + $viewPath = base_path('resources/views/modules/comments'); + $sourcePath = __DIR__.'/../Resources/views'; + + $this->publishes([$sourcePath => $viewPath]); + + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/comments'; + }, \Config::get('view.paths')), [$sourcePath]), 'comments'); + } + + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $langPath = base_path('resources/lang/modules/comments'); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, 'comments'); + } else { + $this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'comments'); + } + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array(); + } + +} diff --git a/modules/Blog/Comments/Resources/lang/en/module.php b/modules/Blog/Comments/Resources/lang/en/module.php new file mode 100644 index 00000000..e83dd573 --- /dev/null +++ b/modules/Blog/Comments/Resources/lang/en/module.php @@ -0,0 +1,6 @@ + 'Comments', + 'description' => "Bring comment support to blog module", + 'overview' => 'All comments' +]; \ No newline at end of file diff --git a/modules/Blog/Comments/start.php b/modules/Blog/Comments/start.php new file mode 100644 index 00000000..7be329cb --- /dev/null +++ b/modules/Blog/Comments/start.php @@ -0,0 +1,15 @@ + Date: Tue, 16 Aug 2016 13:20:30 +0200 Subject: [PATCH 9/9] FIX: fix routes to writing new blog and blog post overview --- modules/Blog/Article/Handlers/Article.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/Blog/Article/Handlers/Article.php b/modules/Blog/Article/Handlers/Article.php index fb4aeb83..90d0f39d 100644 --- a/modules/Blog/Article/Handlers/Article.php +++ b/modules/Blog/Article/Handlers/Article.php @@ -71,7 +71,7 @@ class Article extends Handler // get data and try to save them $data = EditContent::getFields($request, $fields); - $data['allowComments'] = (int) $data['allowComments']; + $data['allowComments'] = (int)$data['allowComments']; list($revision, $changedColumns) = $content->updateWithHistory($fields, $data, $revisionID); @@ -90,8 +90,8 @@ class Article extends Handler $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']); + $sub->route('content.new', trans('article::article.new'), ['id' => self::getModuleId()], 10, ['icon' => 'fa fa-fw fa-pencil']); + $sub->route('content.overview', trans('article::article.overview'), ['id' => self::getModuleId()], 30, ['icon' => 'fa fa-fw fa-book']); }, 10, ['icon' => 'fa fa-fw fa-book']); }