FEATURE #2354 @2h30m: add pipeline for edit and create new content
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Modules\ContactForm\Pipeline\SavePipeline;
|
||||
|
||||
use App\CMS\Contracts\Content\SavePipeline\Process;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
class SaveContactInformation implements Process
|
||||
{
|
||||
/**
|
||||
* Process and modify given page
|
||||
*
|
||||
* @param Content $page
|
||||
* @param array $input
|
||||
*
|
||||
* @return void>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -77,26 +77,26 @@
|
||||
@lang('contactform::admin/content.email')
|
||||
</label>
|
||||
|
||||
<input class="form-control" type="email" name="email" value="{{$page->moduleSettings->email or ""}}" />
|
||||
<input class="form-control" type="email" name="email" value="{{$page->moduleSettings['email'] or ''}}" />
|
||||
|
||||
<label class="label-control">
|
||||
@lang('contactform::admin/content.phone')
|
||||
</label>
|
||||
|
||||
<input class="form-control" type="tel" name="phone" value="{{$page->moduleSettings->phone or ""}}" />
|
||||
<input class="form-control" type="tel" name="phone" value="{{$page->moduleSettings['phone'] or ''}}" />
|
||||
|
||||
<label class="label-control">
|
||||
@lang('contactform::admin/content.compName')
|
||||
</label>
|
||||
|
||||
<input class="form-control" type="text" name="companyName"
|
||||
value="{{$page->moduleSettings->companyName or ""}}" />
|
||||
value="{{$page->moduleSettings['companyName'] or ''}}" />
|
||||
|
||||
<label class="label-control">
|
||||
@lang('contactform::admin/content.address')
|
||||
</label>
|
||||
|
||||
<textarea rows="3" class="form-control" name="address">{{$page->moduleSettings->address or ""}}</textarea>
|
||||
<textarea rows="3" class="form-control" name="address">{{$page->moduleSettings['address'] or ''}}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="column col-lg-6">
|
||||
@@ -105,14 +105,14 @@
|
||||
</label>
|
||||
|
||||
<input class="form-control" type="email" name="contactEmail"
|
||||
value="{{$page->moduleSettings->contactEmail or \Auth::user()->email}}" />
|
||||
value="{{$page->moduleSettings['contactEmail'] or \Auth::user()->email}}" />
|
||||
|
||||
<label class="label-control">
|
||||
@lang('contactform::admin/content.subject')
|
||||
</label>
|
||||
|
||||
<input class="form-control" type="text" name="subject"
|
||||
value="{{$page->moduleSettings->subject or trans('contactform::admin/content.defaultSubject')}}" />
|
||||
value="{{$page->moduleSettings['subject'] or trans('contactform::admin/content.defaultSubject')}}" />
|
||||
|
||||
<div class="row">
|
||||
<div class="column col-lg-6">
|
||||
@@ -120,7 +120,7 @@
|
||||
@lang('contactform::admin/content.gpsLat')
|
||||
</label>
|
||||
|
||||
<input class="form-control" type="text" value="{{$page->moduleSettings->gpsLat or ""}}"
|
||||
<input class="form-control" type="text" value="{{$page->moduleSettings['gpsLat'] or ''}}"
|
||||
name="gpsLat" />
|
||||
</div>
|
||||
<div class="column col-lg-6">
|
||||
@@ -128,7 +128,7 @@
|
||||
@lang('contactform::admin/content.gpsLng')
|
||||
</label>
|
||||
|
||||
<input class="form-control" type="text" value="{{$page->moduleSettings->gpsLng or ""}}"
|
||||
<input class="form-control" type="text" value="{{$page->moduleSettings['gpsLng'] or ''}}"
|
||||
name="gpsLng" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user