FEATURE #2350 @1h: move beforeRender methods into pipeline
This commit is contained in:
@@ -16,28 +16,6 @@ use Modules\Blog\Article\Entities\Comment;
|
||||
|
||||
class Article extends Handler implements ContentTitles, AdvancedContentModifier, InstallableModule
|
||||
{
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$content->comments = new Collection();
|
||||
if (isset($content->moduleSettings['allowComments']) && $content->moduleSettings['allowComments']) {
|
||||
$content->comments = Comment::where('content_id', $content->id)
|
||||
->with('author')
|
||||
->where('approved', 1)
|
||||
->orderBy('created_at')
|
||||
->get();
|
||||
}
|
||||
|
||||
return Controller::VisitorsView($content->template, ['page' => $content, 'extra' => $parameters]);
|
||||
}
|
||||
|
||||
public static function getExtendedFormInputsCreate()
|
||||
{
|
||||
$sections = parent::getExtendedFormInputsCreate();
|
||||
@@ -198,17 +176,6 @@ class Article extends Handler implements ContentTitles, AdvancedContentModifier,
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Load some extra data for content management form?
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function loadExtraData(Content $content)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this module support categories?
|
||||
*
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Modules\Blog\Article\Pipeline\DisplayContent;
|
||||
|
||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
||||
use App\Models\Content\Content;
|
||||
use Illuminate\Support\Collection;
|
||||
use Modules\Blog\Article\Entities\Comment;
|
||||
use Modules\Blog\Article\Handlers\Article;
|
||||
|
||||
class LoadCommentsForBlogpost implements Process
|
||||
{
|
||||
/**
|
||||
* Process and modify given page
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function handle(Content & $content)
|
||||
{
|
||||
if ($content->handler != Article::class)
|
||||
return;
|
||||
|
||||
$content->comments = new Collection();
|
||||
if (isset($content->moduleSettings['allowComments']) && $content->moduleSettings['allowComments']) {
|
||||
$content->comments = Comment::where('content_id', $content->id)
|
||||
->with('author')
|
||||
->where('approved', 1)
|
||||
->orderBy('created_at')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php namespace Modules\Blog\Article\Providers;
|
||||
|
||||
use App\Providers\ModuleServiceProvider;
|
||||
use Modules\Blog\Article\Pipeline\DisplayContent\LoadCommentsForBlogpost;
|
||||
|
||||
class ArticleServiceProvider extends ModuleServiceProvider
|
||||
{
|
||||
@@ -14,6 +15,10 @@ class ArticleServiceProvider extends ModuleServiceProvider
|
||||
parent::boot();
|
||||
|
||||
$this->app->register(ArticleEventServiceProvider::class);
|
||||
|
||||
// load comments for blogpost
|
||||
$pipeline = app('displayPipeline');
|
||||
$pipeline->add(LoadCommentsForBlogpost::class);
|
||||
}
|
||||
|
||||
protected function setModuleAlias()
|
||||
|
||||
Reference in New Issue
Block a user