history = $history; $this->file = $file; $this->content = $content; $this->module = $module; $this->category = $category; $this->template = $template; } /** * Display form for editing static page * * @param $url * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function edit($url) { $statuses = ContentStatuses::getWithTranslations(); $page = $this->content->getOne($url); // get module ID $module = $this->module->getByHandler($page->module_handler); $pageHeading = $this->module->getUpdateContentTitle($module, $page); $templates = $this->template->getForModule($module); $categories = $this->category->getForModule($module); $history = $this->history->getStructuredHistoryOf($page); // modify data for edit form according to installed template call_user_func_array([CurrentTemplate::handler(), 'beforePopulatingEditForm'], [&$page]); // render view return view('admin.content.edit', [ 'pageHeading' => $pageHeading, 'contentStatuses' => $statuses, 'page' => $page, 'module' => $module, 'categories' => $categories, 'rootPages' => $this->content->getOverview(), '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 * @param $id * * @return \Illuminate\Http\RedirectResponse */ public function update(Request $request, $id) { try { /** * @var $page Content */ $page = $this->content->getOne($id); } catch (NotFoundHttpException $e) { // log attempt of invalid edit Event::fire(new AttemptToEditInvalidContent($id)); // page for editing not found return redirect() ->route('content.overview') ->with('error', trans('admin/contents.invalidPage')); } // edit page list($page, $revision, $changedColumns) = Interaction::handle($request, new EditContentInteraction(), $page); // was something changed? if ($changedColumns == 0) { return redirect() ->route('content.edit', ['id' => $page->id]) ->with('error', trans('admin/contents.nothingToEdit')); } // something was changed, inform user return redirect() ->route('content.overview') ->with('success', trans('admin/contents.successfullyEdited')); } /** * Convert object of all request data into array of only wanted fields * * @param Request $request * @param $fields * * @return array */ public static function getFields(Request $request, $fields) { $requestData = []; foreach ($fields as $field) { $requestData[$field] = $request->$field; } return $requestData; } }