FEATURE: change directory structure
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace App\CMS\Widgets\HtmlCode;
|
||||
|
||||
use App\CMS\Contracts\Widgets\PublicWidget;
|
||||
use App\CMS\Widgets\Contracts\WidgetRenderer;
|
||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
||||
use App\Models\Widgets\Widget;
|
||||
|
||||
class HtmlCode implements PublicWidget
|
||||
{
|
||||
/**
|
||||
* Name getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'widgets/htmlCode.widgetName';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return 'widgets/htmlCode.widgetDescription';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for presenter/renderer of this widget
|
||||
*
|
||||
* @return WidgetRenderer
|
||||
*/
|
||||
public static function getPresenter()
|
||||
{
|
||||
return Presenters\HtmlCode::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Widget $widget
|
||||
* @param \stdClass $data
|
||||
*
|
||||
* @return Widget
|
||||
* @throws MissingParameterException
|
||||
*/
|
||||
public static function save(Widget $widget, \stdClass $data)
|
||||
{
|
||||
if (!isset($data->code) || empty($data->code)) {
|
||||
throw new MissingParameterException('code');
|
||||
}
|
||||
|
||||
$widgetSettings = [
|
||||
'code' => $data->code,
|
||||
'containerClass' => isset($data->containerClass) ? $data->containerClass : ''
|
||||
];
|
||||
|
||||
$widget->settings = json_encode($widgetSettings);
|
||||
|
||||
return $widget;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace App\CMS\Widgets\HtmlCode\Presenters;
|
||||
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
use App\CMS\Contracts\Widgets\WidgetRenderer;
|
||||
|
||||
class HtmlCode implements WidgetRenderer
|
||||
{
|
||||
/**
|
||||
* Method used for displaying widget.
|
||||
*
|
||||
* This method renders some HTML code for displaying.
|
||||
*
|
||||
* @param Widget $widget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function render(Widget $widget)
|
||||
{
|
||||
$settings = $widget->settings;
|
||||
$code = '
|
||||
<div class="html-code-widget ' . $widget->container_class . '">
|
||||
' . $settings->code . '
|
||||
</div>';
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for creating new instance of widget
|
||||
*
|
||||
* @param WidgetType $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderAddForm(WidgetType $type)
|
||||
{
|
||||
return view('admin.widgets.htmlCode.new', [
|
||||
'type' => $type,
|
||||
'widget' => new Widget(),
|
||||
'settings' => new \stdClass()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for editing already existing widget
|
||||
*
|
||||
* @param Widget $widget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderEditForm(Widget $widget)
|
||||
{
|
||||
$settings = json_decode($widget->settings);
|
||||
return view('admin.widgets.htmlCode.edit', ['widget' => $widget, 'settings' => $settings]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user