120 lines
3.8 KiB
PHP
120 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Contents;
|
|
|
|
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 App\CMS\Enumerations\ContentStatuses;
|
|
use App\Cms\Handlers\Interactions\Interaction;
|
|
use App\Cms\Interactions\Admin\Content\EditContent as EditContentInteraction;
|
|
use App\Http\Controllers\Admin\Controller;
|
|
use App\Http\Requests\EditContentRequest;
|
|
use App\Http\Requests\Request;
|
|
use App\Models\Content\Content;
|
|
use App\Models\Content\ContentHistory;
|
|
use App\Models\FileManager\File;
|
|
use Illuminate\Support\Collection;
|
|
use Modules\Categories\Contracts\Repositories\Category as ICategory;
|
|
|
|
class EditContent extends Controller
|
|
{
|
|
/**
|
|
* @var ContentHistory
|
|
*/
|
|
private $history;
|
|
/**
|
|
* @var File
|
|
*/
|
|
private $file;
|
|
/**
|
|
* @var IContent
|
|
*/
|
|
private $content;
|
|
/**
|
|
* @var IModuleRepository
|
|
*/
|
|
private $module;
|
|
/**
|
|
* @var ITemplate
|
|
*/
|
|
private $template;
|
|
|
|
/**
|
|
* EditContent constructor.
|
|
* Load ContentHistory and File into this controller
|
|
*
|
|
* @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, IContent $content, IModuleRepository $module, ITemplate $template)
|
|
{
|
|
$this->history = $history;
|
|
$this->file = $file;
|
|
$this->content = $content;
|
|
$this->module = $module;
|
|
$this->template = $template;
|
|
}
|
|
|
|
/**
|
|
* Display form for editing static page
|
|
*
|
|
* @param Content $page
|
|
*
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function edit(Content $page)
|
|
{
|
|
$statuses = ContentStatuses::getWithTranslations();
|
|
|
|
// get module ID
|
|
$module = $this->module->getByHandler($page->moduleHandler);
|
|
$pageHeading = $this->module->getUpdateContentTitle($module, $page);
|
|
$templates = $this->template->getForModule($module);
|
|
$history = $this->history->getStructuredHistoryOf($page);
|
|
|
|
$categories = new Collection();
|
|
if (class_exists(ICategory::class)) {
|
|
$categories = app(ICategory::class)->getForModule($module);
|
|
}
|
|
|
|
// render view
|
|
return view('admin.content.edit', [
|
|
'pageHeading' => $pageHeading,
|
|
'contentStatuses' => $statuses,
|
|
'page' => $page,
|
|
'module' => $module,
|
|
'categories' => $categories,
|
|
'rootPages' => $this->content->getOverview()
|
|
->get(),
|
|
'templates' => $templates,
|
|
'formSectionNames' => $this->module->call($module, 'getExtendedFormSections'),
|
|
'formSections' => $this->module->call($module, 'getExtendedFormInputsEdit'),
|
|
'historySize' => count($history['changesets'])
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Edit static page and save changes into history.
|
|
*
|
|
* @param EditContentRequest|Request $request
|
|
* @param Content $page
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
* @internal param $id
|
|
*/
|
|
public function update(Request $request, Content $page)
|
|
{
|
|
// edit page
|
|
Interaction::handle(EditContentInteraction::class, $request->all(), $page);
|
|
|
|
// something was changed, inform user
|
|
return redirect()
|
|
->route('content.overview')
|
|
->with('success', trans('admin/contents.successfullyEdited'));
|
|
}
|
|
} |