FEATURE: add another repositories
This commit is contained in:
@@ -18,6 +18,10 @@ use Illuminate\Support\Facades\Event;
|
||||
use Modules\Categories\Entities\Category;
|
||||
use Pingpong\Modules\Facades\Module as ModuleInstance;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
||||
use App\CMS\Contracts\Repositories\Module as IModuleRepository;
|
||||
use App\CMS\Contracts\Repositories\Template as ITemplate;
|
||||
use Modules\Categories\Contracts\Repositories\Category as ICategory;
|
||||
|
||||
class EditContent extends Controller
|
||||
{
|
||||
@@ -29,66 +33,70 @@ class EditContent extends Controller
|
||||
* @var File
|
||||
*/
|
||||
private $file;
|
||||
/**
|
||||
* @var IContent
|
||||
*/
|
||||
private $content;
|
||||
/**
|
||||
* @var IModuleRepository
|
||||
*/
|
||||
private $module;
|
||||
/**
|
||||
* @var ICategory
|
||||
*/
|
||||
private $category;
|
||||
/**
|
||||
* @var ITemplate
|
||||
*/
|
||||
private $template;
|
||||
|
||||
/**
|
||||
* EditContent constructor.
|
||||
*
|
||||
* Load ContentHistory and File into this controller
|
||||
*
|
||||
* @param ContentHistory $history
|
||||
* @param File $file
|
||||
* @param ContentHistory $history
|
||||
* @param File $file
|
||||
* @param IContent $content
|
||||
* @param IModuleRepository $module
|
||||
* @param ICategory $category
|
||||
* @param ITemplate $template
|
||||
*/
|
||||
public function __construct(ContentHistory $history, File $file)
|
||||
public function __construct(ContentHistory $history, File $file, IContent $content, IModuleRepository $module, ICategory $category, ITemplate $template)
|
||||
{
|
||||
$this->history = $history;
|
||||
$this->file = $file;
|
||||
$this->content = $content;
|
||||
$this->module = $module;
|
||||
$this->category = $category;
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for editing static page
|
||||
*
|
||||
* @param $id
|
||||
* @param $url
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit($url)
|
||||
{
|
||||
// select all content statuses
|
||||
$statuses = ContentStatuses::getWithTranslations();
|
||||
|
||||
// try to find requested page
|
||||
$page = Content::findOrFail($id);
|
||||
$page->module_settings = json_decode($page->module_settings);
|
||||
$page = $this->content->getOne($url);
|
||||
|
||||
// get module ID
|
||||
$module = Module::where('handler', $page->module_handler)
|
||||
->firstOrFail();
|
||||
|
||||
$pageHeading = trans('admin/contents.edit', ['name' => e($page->title)]);
|
||||
if (is_callable([$module->handler, 'getEditTitle'])) {
|
||||
$pageHeading = call_user_func([$module->handler, 'getEditTitle'], $page);
|
||||
}
|
||||
$pageHeading = $this->module->getUpdateContentTitle($module);
|
||||
$templates = $this->template->getForModule($module);
|
||||
$categories = $this->category->getForModule($module);
|
||||
$history = $this->history->getStructuredHistoryOf($page);
|
||||
|
||||
// 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 && !is_null($categoryModule) && $categoryModule->enabled()) {
|
||||
$categories = Category::where('module_id', $module->id)
|
||||
->get();
|
||||
}
|
||||
|
||||
// modify data for edit form according to installed template
|
||||
call_user_func_array([CurrentTemplate::handler(), 'beforePopulatingEditForm'], [&$page]);
|
||||
|
||||
$history = $this->history->getStructuredHistoryOf($page);
|
||||
|
||||
// render view
|
||||
return view('admin.content.edit', [
|
||||
'pageHeading' => $pageHeading,
|
||||
@@ -96,11 +104,8 @@ class EditContent extends Controller
|
||||
'page' => $page,
|
||||
'module' => $module,
|
||||
'categories' => $categories,
|
||||
'rootPages' => $page->getOverview()
|
||||
->where('contents.id', '!=', $page->id)
|
||||
->get(),
|
||||
'rootPages' => $this->content->getOverview(),
|
||||
'templates' => $templates,
|
||||
'extraData' => call_user_func([$page->module_handler, 'loadExtraData'], $page),
|
||||
'formSectionNames' => call_user_func([$page->module_handler, 'getExtendedFormSections']),
|
||||
'formSections' => call_user_func([$page->module_handler, 'getExtendedFormInputsEdit']),
|
||||
'historySize' => count($history['changesets'])
|
||||
|
||||
Reference in New Issue
Block a user