64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?php
|
|
namespace App\Widgets\HtmlCode;
|
|
|
|
use App\Http\Requests\Request;
|
|
use App\Models\Widget;
|
|
use App\Widgets\Contracts\WidgetRenderer;
|
|
use App\Widgets\Exceptions\MissingParameterException;
|
|
use App\Widgets\NonInstallableWidget;
|
|
|
|
class HtmlCode extends NonInstallableWidget
|
|
{
|
|
/**
|
|
* 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;
|
|
}
|
|
} |