1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ElementalBlocks\Block; |
4
|
|
|
|
5
|
|
|
use SilverStripe\ElementalBlocks\Model\Link; |
6
|
|
|
use SilverStripe\Forms\FieldList; |
7
|
|
|
use SilverStripe\Forms\HiddenField; |
8
|
|
|
|
9
|
|
|
class BannerBlock extends FileBlock |
10
|
|
|
{ |
11
|
|
|
private static $db = [ |
|
|
|
|
12
|
|
|
'Content' => 'HTMLText', |
13
|
|
|
]; |
14
|
|
|
|
15
|
|
|
private static $has_one = [ |
|
|
|
|
16
|
|
|
'ImageLink' => Link::class, |
17
|
|
|
'CallToActionLink' => Link::class, |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
private static $singular_name = 'banner'; |
|
|
|
|
21
|
|
|
|
22
|
|
|
private static $plural_name = 'banners'; |
|
|
|
|
23
|
|
|
|
24
|
|
|
public function getType() |
25
|
|
|
{ |
26
|
|
|
return _t(__CLASS__ . '.BlockType', 'Banner'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getCMSFields() |
30
|
|
|
{ |
31
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
32
|
|
|
// Remove default scaffolded relationship fields |
33
|
|
|
$fields->removeByName('ImageLinkID'); |
34
|
|
|
$fields->removeByName('CallToActionLinkID'); |
35
|
|
|
|
36
|
|
|
// Create hidden inputs for JSON input from the "insert link" modal |
37
|
|
|
$fields->addFieldsToTab('Root.Main', [ |
38
|
|
|
HiddenField::create('ImageLinkData'), |
|
|
|
|
39
|
|
|
HiddenField::create('CallToActionLinkData'), |
40
|
|
|
]); |
41
|
|
|
|
42
|
|
|
// Move the file upload field to the right place in the UI |
43
|
|
|
$upload = $fields->fieldByName('Root.Main.File'); |
44
|
|
|
$fields->insertBefore('Content', $upload); |
45
|
|
|
|
46
|
|
|
// Set the height of the content fields |
47
|
|
|
$fields->fieldByName('Root.Main.Content')->setRows(5); |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
return parent::getCMSFields(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.