FEATURE: move contactform into own repository

This commit is contained in:
Michal Kváček
2017-08-22 20:17:39 +02:00
commit 6b0509a1db
36 changed files with 1039 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace Modules\ContactForm\Widgets\Form;
use App\CMS\Contracts\Widgets\PublicWidget;
use App\CMS\Contracts\Widgets\WidgetRenderer;
use App\Http\Requests\Request;
use App\Models\Widgets\Widget;
class Form implements PublicWidget
{
/**
* Name getter
*
* @return string
*/
public static function getName()
{
return 'contactform::admin/widgets.form.name';
}
/**
* Getter for description
*
* @return string
*/
public static function getDescription()
{
return 'contactform::admin/widgets.form.description';
}
/**
* Getter for presenter/renderer of this widget
*
* @return WidgetRenderer
*/
public static function getPresenter()
{
return Presenter::class;
}
/**
* @param Widget $widget
* @param \stdClass $data
*
* @return mixed
*/
public static function save(Request $data)
{
return ['contactFormId' => $data->contactFormId];
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
namespace Modules\ContactForm\Widgets\Form;
use App\Models\Content\Content;
use App\Models\Widgets\Widget;
use App\Models\Widgets\WidgetType;
use App\CMS\Contracts\Widgets\WidgetRenderer;
class Presenter implements WidgetRenderer
{
public static $template = null;
/**
* Method used for displaying widget.
*
* This method renders some HTML code for displaying.
*
* @param Widget $widget
*
* @return mixed
* @throws \ErrorException
*/
public static function render(Widget $widget)
{
if (!self::$template) {
throw new \ErrorException('Cannot render contact form without template! Please, set Presenter::$template variable before rendering.');
}
$form = Content::find($widget->settings->contactFormId);
if (!$form) {
return null;
}
return view(self::$template, ['widget' => $widget, 'form' => $form]);
}
/**
* Display form for creating new instance of widget
*
* @param WidgetType $type
*
* @return mixed
*/
public static function renderAddForm(WidgetType $type)
{
$contactForms = Content::where('moduleHandler', config('contactform.handler'))
->get();
return view('contactform::admin.widgets.form.new', [
'type' => $type,
'widget' => new Widget(),
'forms' => $contactForms
]);
}
/**
* Display form for editing already existing widget
*
* @param Widget $widget
*
* @return mixed
*/
public static function renderEditForm(Widget $widget)
{
$contactForms = Content::where('moduleHandler', config('contactform.handler'))
->get();
return view('contactform::admin.widgets.address.edit', [
'widget' => $widget,
'forms' => $contactForms
]);
}
}