63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?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;
|
|
}
|
|
} |