2019-12-11 03:30:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace Site\Widgets;
|
|
|
|
|
|
|
|
use SilverStripe\AssetAdmin\Forms\UploadField;
|
|
|
|
use SilverStripe\Assets\Image;
|
|
|
|
use SilverStripe\Widgets\Model\Widget;
|
2021-01-13 20:03:21 +01:00
|
|
|
use Site\Extensions\ElementImageWidget;
|
2019-12-11 03:30:39 +01:00
|
|
|
|
|
|
|
if (!class_exists(Widget::class)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
class BannerWidget extends Widget
|
|
|
|
{
|
|
|
|
private static $title = 'Banner';
|
|
|
|
private static $cmsTitle = 'Banner';
|
|
|
|
private static $description = 'Shows banner with image and link.';
|
|
|
|
private static $icon = '<i class="icon font-icon-block-banner"></i>';
|
|
|
|
private static $table_name = 'BannerWidget';
|
|
|
|
|
|
|
|
private static $has_one = [
|
|
|
|
'Image' => Image::class,
|
|
|
|
];
|
|
|
|
|
|
|
|
private static $owns = [
|
|
|
|
'Image',
|
2021-01-13 20:03:21 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
private static $extensions = [
|
|
|
|
ElementImageWidget::class,
|
2019-12-11 03:30:39 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
2021-01-13 20:03:21 +01:00
|
|
|
$fields->push(UploadField::create('Image', 'Image')
|
2019-12-11 03:30:39 +01:00
|
|
|
->setAllowedFileCategories(['image/supported']));
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
2021-01-13 20:03:21 +01:00
|
|
|
|
|
|
|
public function getSibling()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-11 03:30:39 +01:00
|
|
|
}
|