From 9bec808d3818df4daa6373593fd4ed2faac52db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Fri, 10 Mar 2017 09:52:12 +0100 Subject: [PATCH] FEATURE #2354 @2h30m: add pipeline for edit and create new content --- .../Content/AdvancedContentModifier.php | 21 ----- .../Content/DisplayPipeline/Pipeline.php | 5 +- .../Content/SavePipeline/Pipeline.php | 25 ++++++ .../Content/SavePipeline/Process.php | 16 ++++ app/CMS/Contracts/Modules/AppHandler.php | 10 --- app/CMS/Contracts/Modules/TemplateHandler.php | 17 ---- app/CMS/Helpers/CurrentTemplate.php | 33 -------- .../Admin/Content/EditContent.php | 22 +----- .../Interactions/Admin/Content/NewContent.php | 21 +---- ...splayPipeline.php => AbstractPipeline.php} | 79 +++++-------------- .../DisplayPipeline/DisplayPipeline.php | 58 ++++++++++++++ .../Process/AddViewedToPage.php | 2 +- .../Process/CompileShortcodes.php | 2 +- .../SavePipeline/Process/SaveCommonFields.php | 20 +++++ .../Process/UploadRelatedFiles.php} | 52 +++++------- .../SavePipeline/Process/UploadTitlePhoto.php | 33 ++++++++ .../Pipeline/SavePipeline/SavePipeline.php | 69 ++++++++++++++++ .../Admin/Contents/CreateNewContent.php | 5 +- .../Admin/Contents/EditContent.php | 8 +- app/Models/Content/Content.php | 2 +- .../Content/ModelTraits/ContentHistory.php | 2 +- app/Providers/AppServiceProvider.php | 25 +++++- modules/Blog/Article/Handlers/Article.php | 35 -------- .../LoadCommentsForBlogpost.php | 2 +- .../SaveContent/TurnCommentsOnOrOff.php | 29 +++++++ .../Providers/ArticleServiceProvider.php | 6 +- .../DisplayContent/LoadArticlesForList.php | 2 +- modules/ContactForm/Handlers/ContactForm.php | 41 ---------- .../SavePipeline/SaveContactInformation.php | 35 ++++++++ .../Providers/ContactFormServiceProvider.php | 3 + .../views/admin/form/basicInfo.blade.php | 16 ++-- .../content/formParts/appearance.blade.php | 4 +- 32 files changed, 381 insertions(+), 319 deletions(-) create mode 100644 app/CMS/Contracts/Content/SavePipeline/Pipeline.php create mode 100644 app/CMS/Contracts/Content/SavePipeline/Process.php rename app/CMS/Pipeline/{DisplayPipeline.php => AbstractPipeline.php} (52%) create mode 100644 app/CMS/Pipeline/DisplayPipeline/DisplayPipeline.php rename app/CMS/Pipeline/{ => DisplayPipeline}/Process/AddViewedToPage.php (86%) rename app/CMS/Pipeline/{ => DisplayPipeline}/Process/CompileShortcodes.php (87%) create mode 100644 app/CMS/Pipeline/SavePipeline/Process/SaveCommonFields.php rename app/{Models/Content/ModelTraits/Content.php => CMS/Pipeline/SavePipeline/Process/UploadRelatedFiles.php} (55%) create mode 100644 app/CMS/Pipeline/SavePipeline/Process/UploadTitlePhoto.php create mode 100644 app/CMS/Pipeline/SavePipeline/SavePipeline.php create mode 100644 modules/Blog/Article/Pipeline/SaveContent/TurnCommentsOnOrOff.php create mode 100644 modules/ContactForm/Pipeline/SavePipeline/SaveContactInformation.php diff --git a/app/CMS/Contracts/Content/AdvancedContentModifier.php b/app/CMS/Contracts/Content/AdvancedContentModifier.php index 6956dd9b..03ba33f1 100644 --- a/app/CMS/Contracts/Content/AdvancedContentModifier.php +++ b/app/CMS/Contracts/Content/AdvancedContentModifier.php @@ -5,27 +5,6 @@ use App\Http\Requests\Request; use App\Models\Content\Content; interface AdvancedContentModifier { - /** - * Save module-specific values into database - * - * @param Content $content - * @param array $inputData - * - * @return mixed - */ - public static function createNew(Content &$content, array $inputData); - - /** - * 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 - * - * @return mixed - */ - public static function edit(Content $content, $request); /** * Method called right after content page is marked as deleted * diff --git a/app/CMS/Contracts/Content/DisplayPipeline/Pipeline.php b/app/CMS/Contracts/Content/DisplayPipeline/Pipeline.php index ee867d53..1736f35a 100644 --- a/app/CMS/Contracts/Content/DisplayPipeline/Pipeline.php +++ b/app/CMS/Contracts/Content/DisplayPipeline/Pipeline.php @@ -7,10 +7,9 @@ interface Pipeline { /** * Add new process into pipeline * - * @param Process $proces - * - * @return mixed + * @param string $process * + * @return void */ function add($process); function run(Content $page); diff --git a/app/CMS/Contracts/Content/SavePipeline/Pipeline.php b/app/CMS/Contracts/Content/SavePipeline/Pipeline.php new file mode 100644 index 00000000..6d9cdbbd --- /dev/null +++ b/app/CMS/Contracts/Content/SavePipeline/Pipeline.php @@ -0,0 +1,25 @@ +run($page, $data); - // upload file - if provided - $data['titlePhoto'] = isset($data['existingTitlePhoto']) ? $data['existingTitlePhoto'] : null; - - if (!is_null($titlePhoto)) { - $file = $this->file->upload($titlePhoto); - $data['titlePhoto'] = $file ? $file['filename'] : null; - } - - $page->update($data); - $this->module->callOnString($page->moduleHandler, 'edit', [$page, $data]); - - // move to interaction - $keepAssigned = isset($data['keepAssigned']) ? $data['keepAssigned'] : []; - $page->uploadRelatedFiles($relatedFiles, $keepAssigned); + return $page; } /** diff --git a/app/CMS/Interactions/Admin/Content/NewContent.php b/app/CMS/Interactions/Admin/Content/NewContent.php index b65d7ee0..348a0733 100644 --- a/app/CMS/Interactions/Admin/Content/NewContent.php +++ b/app/CMS/Interactions/Admin/Content/NewContent.php @@ -43,29 +43,14 @@ class NewContent implements Interaction */ public function handle($data, $parameters) { - list($moduleHandler, $titlePhoto, $relatedFiles) = $parameters; - - // upload file - if provided - $file = !is_null($titlePhoto) ? $this->file->upload($titlePhoto) : null; + list($moduleHandler) = $parameters; $data['userId'] = \Auth::user()->id; $data['language'] = LaravelLocalization::getCurrentLocale(); - $data['titlePhoto'] = $file ? $file['filename'] : null; $data['moduleHandler'] = $moduleHandler; - $page = Content::create($data); - - // save module-specific stuff - $this->module->callOnString($moduleHandler, 'createNew', [&$page, $data]); - - // let template to modify data and content page - CurrentTemplate::beforeSave($page, $data); - - // save content of page before (possible) uploading related files - $page->save(); - - // upload files assigned to content page - $page->uploadRelatedFiles($relatedFiles); + $page = new Content(); + app('saveContentPipeline')->run($page, $data); return $page; } diff --git a/app/CMS/Pipeline/DisplayPipeline.php b/app/CMS/Pipeline/AbstractPipeline.php similarity index 52% rename from app/CMS/Pipeline/DisplayPipeline.php rename to app/CMS/Pipeline/AbstractPipeline.php index 91f2bb5d..de9b4215 100644 --- a/app/CMS/Pipeline/DisplayPipeline.php +++ b/app/CMS/Pipeline/AbstractPipeline.php @@ -1,17 +1,30 @@ acceptedProcessInterface)) + return; + + if (!in_array($this->acceptedProcessInterface, class_implements($classname))) { + throw new InvalidProcessType($classname); + } + } /** * Add new process into pipeline @@ -28,20 +41,6 @@ class DisplayPipeline implements Pipeline $this->processes[] = $process; } - /** - * check if given classname implements Process interface - * - * @param $classname - * - * @throws InvalidProcessType - */ - protected function checkValidProcess($classname) - { - if (!in_array(Process::class, class_implements($classname))) { - throw new InvalidProcessType($classname); - } - } - /** * @param null $beforeStart */ @@ -69,44 +68,4 @@ class DisplayPipeline implements Pipeline $this->beforeRender = $beforeRender; } - - /** - * Run pipeline - * - * @param Content $page - * - * @return Content - */ - function run(Content $page) - { - $this->runBeforeStart($page); - - foreach ($this->processes as $process) { - /** - * @var $run Process - */ - $run = new $process; - $run->handle($page); - } - - $this->runBeforeRender($page); - - return $page; - } - - private function runBeforeStart($page) - { - if (!is_null($this->beforeStart)) { - $process = new $this->beforeStart; - $process->handle($page); - } - } - - private function runBeforeRender($page) - { - if (!is_null($this->beforeRender)) { - $process = new $this->beforeRender; - $process->handle($page); - } - } } \ No newline at end of file diff --git a/app/CMS/Pipeline/DisplayPipeline/DisplayPipeline.php b/app/CMS/Pipeline/DisplayPipeline/DisplayPipeline.php new file mode 100644 index 00000000..9feda74d --- /dev/null +++ b/app/CMS/Pipeline/DisplayPipeline/DisplayPipeline.php @@ -0,0 +1,58 @@ +acceptedProcessInterface = Process::class; + } + + /** + * Run pipeline + * + * @param Content $page + * + * @return Content + */ + function run(Content $page) + { + $this->runBeforeStart($page); + + foreach ($this->processes as $process) { + /** + * @var $run Process + */ + $run = new $process; + $run->handle($page); + } + + $this->runBeforeRender($page); + + return $page; + } + + protected function runBeforeStart($page) + { + if (!is_null($this->beforeStart)) { + $process = new $this->beforeStart; + $process->handle($page); + } + } + + protected function runBeforeRender($page) + { + if (!is_null($this->beforeRender)) { + $process = new $this->beforeRender; + $process->handle($page); + } + } +} \ No newline at end of file diff --git a/app/CMS/Pipeline/Process/AddViewedToPage.php b/app/CMS/Pipeline/DisplayPipeline/Process/AddViewedToPage.php similarity index 86% rename from app/CMS/Pipeline/Process/AddViewedToPage.php rename to app/CMS/Pipeline/DisplayPipeline/Process/AddViewedToPage.php index d29be5d4..870269a9 100644 --- a/app/CMS/Pipeline/Process/AddViewedToPage.php +++ b/app/CMS/Pipeline/DisplayPipeline/Process/AddViewedToPage.php @@ -1,5 +1,5 @@ exists == false) ? $page = Content::create($input): $page->update($input); + } +} \ No newline at end of file diff --git a/app/Models/Content/ModelTraits/Content.php b/app/CMS/Pipeline/SavePipeline/Process/UploadRelatedFiles.php similarity index 55% rename from app/Models/Content/ModelTraits/Content.php rename to app/CMS/Pipeline/SavePipeline/Process/UploadRelatedFiles.php index 6b4a8206..447897f0 100644 --- a/app/Models/Content/ModelTraits/Content.php +++ b/app/CMS/Pipeline/SavePipeline/Process/UploadRelatedFiles.php @@ -1,32 +1,33 @@ removeRelatedFiles($revisionId, $assignedFiles); + $this->removeRelatedFiles($page, $assignedFiles); // allow uploading only on created pages - if (!$this->id || !$files[0]) { - return $changed; + if (!$page->id || !$files[0]) { + return; } // find or create new directory for files assigned to content @@ -37,7 +38,7 @@ trait Content $data = new \stdClass(); $data->directoryId = $directory->id; - $fileModel = App::make(File::class); + $fileModel = app(File::class); foreach ($files as $file) { if (!$file) { @@ -48,38 +49,27 @@ trait Content // add assignement ContentHasFile::create([ 'file_id' => $uploaded['id'], - 'content_id' => $this->id + 'content_id' => $page->id ]); - - if ($revisionId) { - $this->saveHistory($revisionId, 'file', null, ['file' => $uploaded['file']->getClientOriginalName()]); - } - - $changed++; } - - return $changed; } /** * Delete files from association * - * @param $revisionId - * - * @return int + * @param Content $page + * @param $assignedFiles */ - private function removeRelatedFiles($revisionId, $assignedFiles) + private function removeRelatedFiles(Content $page, $assignedFiles) { - $allFiles = $this->files() + $allFiles = $page->files() ->whereNotIn('id', array_keys($assignedFiles)) ->get(); foreach ($allFiles as $file) { - ContentHasFile::where('content_id', $this->id) + ContentHasFile::where('content_id', $page->id) ->where('file_id', $file->id) ->delete(); } - - return count($allFiles); } } \ No newline at end of file diff --git a/app/CMS/Pipeline/SavePipeline/Process/UploadTitlePhoto.php b/app/CMS/Pipeline/SavePipeline/Process/UploadTitlePhoto.php new file mode 100644 index 00000000..3ea87338 --- /dev/null +++ b/app/CMS/Pipeline/SavePipeline/Process/UploadTitlePhoto.php @@ -0,0 +1,33 @@ +titlePhoto = isset($input['existingTitlePhoto']) ? $input['existingTitlePhoto'] : null; + + if (!is_null($titlePhoto)) { + $file = $fileModel->upload($titlePhoto); + + $page->titlePhoto = $file ? $file['filename'] : null; + } + + $page->save(); + } +} \ No newline at end of file diff --git a/app/CMS/Pipeline/SavePipeline/SavePipeline.php b/app/CMS/Pipeline/SavePipeline/SavePipeline.php new file mode 100644 index 00000000..efe69ebd --- /dev/null +++ b/app/CMS/Pipeline/SavePipeline/SavePipeline.php @@ -0,0 +1,69 @@ +acceptedProcessInterface = Process::class; + } + + /** + * Save content page + * + * @param Content $page + * @param array $input + * + * @return Content + */ + function run(Content & $page, array $input) + { + $this->runBeforeStart($page, $input); + + foreach ($this->processes as $process) { + /** + * @var $run Process + */ + $run = new $process; + $run->handle($page, $input); + } + + $this->runAfter($page, $input); + + return $page; + } + + /** + * Run process as first - if specified + * + * @param Content $page + * @param array $input + */ + protected function runBeforeStart(Content $page, array $input) + { + if (!is_null($this->beforeStart)) { + app($this->beforeStart)->handle($page, $input); + } + } + + /** + * Run some process in the end - if exists + * + * @param Content $page + * @param array $input + */ + protected function runAfter(Content $page, array $input) + { + if (!is_null($this->beforeRender)) { + app($this->beforeRender)->handle($page, $input); + } + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Admin/Contents/CreateNewContent.php b/app/Http/Controllers/Admin/Contents/CreateNewContent.php index 6abe97e5..9a494e5c 100644 --- a/app/Http/Controllers/Admin/Contents/CreateNewContent.php +++ b/app/Http/Controllers/Admin/Contents/CreateNewContent.php @@ -103,11 +103,8 @@ class CreateNewContent extends Controller { $module = $this->module->getOne($moduleId); - $titlePhoto = $request->file('titlePhoto'); - $relatedFiles = $request->all()['files']; - // create new page - Interaction::handle(NewContent::class, $request->all(), $module->handler, $titlePhoto, $relatedFiles); + Interaction::handle(NewContent::class, $request->all(), $module->handler); return redirect() ->route('content.overview') diff --git a/app/Http/Controllers/Admin/Contents/EditContent.php b/app/Http/Controllers/Admin/Contents/EditContent.php index b18c1dad..e39d0e8c 100644 --- a/app/Http/Controllers/Admin/Contents/EditContent.php +++ b/app/Http/Controllers/Admin/Contents/EditContent.php @@ -87,9 +87,6 @@ class EditContent extends Controller $categories = $this->category->getForModule($module); $history = $this->history->getStructuredHistoryOf($page); - // modify data for edit form according to installed template - CurrentTemplate::beforePopulatingEditForm($page); - // render view return view('admin.content.edit', [ 'pageHeading' => $pageHeading, @@ -132,10 +129,7 @@ class EditContent extends Controller } // edit page - $titlePhoto = $request->file('titlePhoto'); - $relatedFiles = $request->all()['files']; - - Interaction::handle(EditContentInteraction::class, $request->all(), $page, $titlePhoto, $relatedFiles); + Interaction::handle(EditContentInteraction::class, $request->all(), $page); // something was changed, inform user return redirect() diff --git a/app/Models/Content/Content.php b/app/Models/Content/Content.php index 8361c3ff..e016392b 100644 --- a/app/Models/Content/Content.php +++ b/app/Models/Content/Content.php @@ -17,7 +17,7 @@ use Modules\Categories\Entities\Category; */ class Content extends Model { - use SoftDeletes, ModelTraits\Content, Nullable; + use SoftDeletes, Nullable; public $timestamps = true; protected $fillable = [ 'userId', diff --git a/app/Models/Content/ModelTraits/ContentHistory.php b/app/Models/Content/ModelTraits/ContentHistory.php index 791d89dc..3b92184f 100644 --- a/app/Models/Content/ModelTraits/ContentHistory.php +++ b/app/Models/Content/ModelTraits/ContentHistory.php @@ -10,7 +10,7 @@ trait ContentHistory /** * Returns history grouped by revisions (edit_batches) * - * @param Content $content + * @param ContentModel $content * * @return array */ diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 0dc3d2e5..e25b2de4 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -13,9 +13,13 @@ use App\CMS\Handlers\Search\Content; use App\CMS\Handlers\Search\Files; use App\CMS\Handlers\Search\Presenters\AdminContent as AdminContentPresenter; use App\CMS\Handlers\Search\Presenters\AdminFiles; -use App\CMS\Pipeline\DisplayPipeline; -use App\CMS\Pipeline\Process\AddViewedToPage; -use App\CMS\Pipeline\Process\CompileShortcodes; +use App\CMS\Pipeline\DisplayPipeline\DisplayPipeline; +use App\CMS\Pipeline\DisplayPipeline\Process\AddViewedToPage; +use App\CMS\Pipeline\DisplayPipeline\Process\CompileShortcodes; +use App\CMS\Pipeline\SavePipeline\Process\SaveCommonFields; +use App\CMS\Pipeline\SavePipeline\Process\UploadRelatedFiles; +use App\CMS\Pipeline\SavePipeline\Process\UploadTitlePhoto; +use App\CMS\Pipeline\SavePipeline\SavePipeline; use App\CMS\Repositories\Content\Content as ContentRepository; use App\CMS\Repositories\Module as ModuleRepository; use App\CMS\Repositories\Templates\Template as TemplateRepository; @@ -45,6 +49,7 @@ class AppServiceProvider extends ServiceProvider $this->registerSettings(); $this->registerSearch(); $this->registerDisplayPipeline(); + $this->registerSavePipeline(); } } @@ -73,6 +78,11 @@ class AppServiceProvider extends ServiceProvider return new DisplayPipeline(); }); + // create singleton for display pipeline - pipeline used for displaying visitor pages + $this->app->singleton('saveContentPipeline', function ($app) { + return new SavePipeline(); + }); + // create registrator for template directories $this->app->singleton('registerTemplateDir', function ($app) { return new TemplateRegistrator($app); @@ -132,4 +142,13 @@ class AppServiceProvider extends ServiceProvider $registrator->add(AddViewedToPage::class); $registrator->add(CompileShortcodes::class); } + + private function registerSavePipeline() + { + $pipeline = $this->app->make('saveContentPipeline'); + + $pipeline->add(SaveCommonFields::class); + $pipeline->add(UploadTitlePhoto::class); + $pipeline->add(UploadRelatedFiles::class); + } } diff --git a/modules/Blog/Article/Handlers/Article.php b/modules/Blog/Article/Handlers/Article.php index 1db036e1..9a2b2615 100644 --- a/modules/Blog/Article/Handlers/Article.php +++ b/modules/Blog/Article/Handlers/Article.php @@ -30,41 +30,6 @@ class Article extends Handler implements ContentTitles, AdvancedContentModifier, return self::getExtendedFormInputsCreate(); } - /** - * Save module-specific values into database - * - * @param Content $content - * @param Request $request - * - * @return mixed|void - */ - public static function createNew(Content &$content, array $inputData) - { - $content->moduleSettings = ['allowComments' => (int)isset($inputData['allowComments'])]; - } - - /** - * 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 - * - * @return void - */ - public static function edit(Content $content, $request) - { - $settings = $content->moduleSettings; - if (!is_object($settings)) - $settings = new \stdClass(); - - $settings->allowComments = isset($request['allowComments']) ? (int)$request['allowComments'] : 0; - - $content->moduleSettings = $settings; - $content->save(); - } - /** * Register admin menu * diff --git a/modules/Blog/Article/Pipeline/DisplayContent/LoadCommentsForBlogpost.php b/modules/Blog/Article/Pipeline/DisplayContent/LoadCommentsForBlogpost.php index 3f7b606a..575f9249 100644 --- a/modules/Blog/Article/Pipeline/DisplayContent/LoadCommentsForBlogpost.php +++ b/modules/Blog/Article/Pipeline/DisplayContent/LoadCommentsForBlogpost.php @@ -18,7 +18,7 @@ class LoadCommentsForBlogpost implements Process */ function handle(Content & $content) { - if ($content->handler != Article::class) + if ($content->moduleHandler != Article::class) return; $content->comments = new Collection(); diff --git a/modules/Blog/Article/Pipeline/SaveContent/TurnCommentsOnOrOff.php b/modules/Blog/Article/Pipeline/SaveContent/TurnCommentsOnOrOff.php new file mode 100644 index 00000000..0571fdc7 --- /dev/null +++ b/modules/Blog/Article/Pipeline/SaveContent/TurnCommentsOnOrOff.php @@ -0,0 +1,29 @@ +moduleHandler !== Article::class) { + return; + } + + $settings = $content->moduleSettings; + $settings['allowComments'] = isset($input['allowComments']) ? (int)$input['allowComments'] : 0; + $content->moduleSettings = $settings; + $content->save(); + } +} \ No newline at end of file diff --git a/modules/Blog/Article/Providers/ArticleServiceProvider.php b/modules/Blog/Article/Providers/ArticleServiceProvider.php index 6ba07271..bae25fe8 100644 --- a/modules/Blog/Article/Providers/ArticleServiceProvider.php +++ b/modules/Blog/Article/Providers/ArticleServiceProvider.php @@ -2,6 +2,7 @@ use App\Providers\ModuleServiceProvider; use Modules\Blog\Article\Pipeline\DisplayContent\LoadCommentsForBlogpost; +use Modules\Blog\Article\Pipeline\SaveContent\TurnCommentsOnOrOff; class ArticleServiceProvider extends ModuleServiceProvider { @@ -17,8 +18,9 @@ class ArticleServiceProvider extends ModuleServiceProvider $this->app->register(ArticleEventServiceProvider::class); // load comments for blogpost - $pipeline = app('displayPipeline'); - $pipeline->add(LoadCommentsForBlogpost::class); + app('displayPipeline')->add(LoadCommentsForBlogpost::class); + + app('saveContentPipeline')->add(TurnCommentsOnOrOff::class); } protected function setModuleAlias() diff --git a/modules/Blog/ArticleList/Pipeline/DisplayContent/LoadArticlesForList.php b/modules/Blog/ArticleList/Pipeline/DisplayContent/LoadArticlesForList.php index 7e7b06c1..6d93c5f1 100644 --- a/modules/Blog/ArticleList/Pipeline/DisplayContent/LoadArticlesForList.php +++ b/modules/Blog/ArticleList/Pipeline/DisplayContent/LoadArticlesForList.php @@ -24,7 +24,7 @@ class LoadArticlesForList implements Process function handle(Content & $page) { // load articles only for article list - if ($page->handler != ArticleList::class) + if ($page->moduleHandler != ArticleList::class) return; $articles = ArticleModel::where('moduleHandler', Article::class) diff --git a/modules/ContactForm/Handlers/ContactForm.php b/modules/ContactForm/Handlers/ContactForm.php index cf53c414..6763d513 100644 --- a/modules/ContactForm/Handlers/ContactForm.php +++ b/modules/ContactForm/Handlers/ContactForm.php @@ -16,47 +16,6 @@ class ContactForm extends Handler implements ContentTitles, AdvancedContentModif return ContactFormHistory::class; } - /** - * Save module-specific values into database - * - * @param Content $content - * @param array $inputData - * - * @return mixed|void - */ - public static function createNew(Content &$content, array $inputData) - { - $settings = [ - 'phone' => $inputData['phone'], - 'email' => $inputData['email'], - 'contactEmail' => $inputData['contactEmail'], - 'subject' => $inputData['subject'], - 'companyName' => $inputData['companyName'], - 'address' => $inputData['address'], - 'gpsLat' => $inputData['gpsLat'], - 'gpsLng' => $inputData['gpsLng'], - ]; - - // save settings - $content->moduleSettings = $settings; - } - - /** - * 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 - * - * @return mixed|void - */ - public static function edit(Content $content, $request) - { - self::createNew($content, $request); - $content->save(); - } - public static function getModuleId() { $handler = config('contactform.handler'); diff --git a/modules/ContactForm/Pipeline/SavePipeline/SaveContactInformation.php b/modules/ContactForm/Pipeline/SavePipeline/SaveContactInformation.php new file mode 100644 index 00000000..43fa6e3c --- /dev/null +++ b/modules/ContactForm/Pipeline/SavePipeline/SaveContactInformation.php @@ -0,0 +1,35 @@ + + */ + function handle(Content & $page, array & $input) + { + + $settings = [ + 'phone' => $input['phone'], + 'email' => $input['email'], + 'contactEmail' => $input['contactEmail'], + 'subject' => $input['subject'], + 'companyName' => $input['companyName'], + 'address' => $input['address'], + 'gpsLat' => $input['gpsLat'], + 'gpsLng' => $input['gpsLng'], + ]; + + // save settings + $page->moduleSettings = $settings; + $page->save(); + } +} \ No newline at end of file diff --git a/modules/ContactForm/Providers/ContactFormServiceProvider.php b/modules/ContactForm/Providers/ContactFormServiceProvider.php index a0a64438..a04f0762 100644 --- a/modules/ContactForm/Providers/ContactFormServiceProvider.php +++ b/modules/ContactForm/Providers/ContactFormServiceProvider.php @@ -2,6 +2,7 @@ use App\Providers\ModuleServiceProvider; use Modules\ContactForm\Handlers\ContactForm; +use Modules\ContactForm\Pipeline\SavePipeline\SaveContactInformation; use Modules\ContactForm\Widgets\Address\Address; use Modules\ContactForm\Widgets\Form\Form; @@ -16,6 +17,8 @@ class ContactFormServiceProvider extends ModuleServiceProvider { parent::boot(); $this->registerWidgets(); + + app('saveContentPipeline')->add(SaveContactInformation::class); } /** diff --git a/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php b/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php index ceeb0a5b..184df299 100644 --- a/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php +++ b/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php @@ -77,26 +77,26 @@ @lang('contactform::admin/content.email') - + - + + value="{{$page->moduleSettings['companyName'] or ''}}" /> - +
@@ -105,14 +105,14 @@ + value="{{$page->moduleSettings['contactEmail'] or \Auth::user()->email}}" /> + value="{{$page->moduleSettings['subject'] or trans('contactform::admin/content.defaultSubject')}}" />
@@ -120,7 +120,7 @@ @lang('contactform::admin/content.gpsLat') -
@@ -128,7 +128,7 @@ @lang('contactform::admin/content.gpsLng') -
diff --git a/resources/views/admin/content/formParts/appearance.blade.php b/resources/views/admin/content/formParts/appearance.blade.php index 253db68f..8c20e63d 100644 --- a/resources/views/admin/content/formParts/appearance.blade.php +++ b/resources/views/admin/content/formParts/appearance.blade.php @@ -18,9 +18,9 @@ - + - @include('admin.snippets.hasError', ['field' => 'titlePhoto']) + @include('admin.snippets.hasError', ['field' => 'titlePhotoFile'])