1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Models a Content Block Tile Section |
5
|
|
|
* |
6
|
|
|
* @since 1.0.0 |
7
|
|
|
*/ |
8
|
|
|
class ContentBlock_TileSection extends ContentBlock |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
private static $db = [ |
|
|
|
|
11
|
|
|
'TilesPerRow' => 'Enum("One, Two, Three")', |
12
|
|
|
'TileTemplate' => 'Text' |
13
|
|
|
]; |
14
|
|
|
|
15
|
|
|
private static $has_many = [ |
|
|
|
|
16
|
|
|
'ContentTiles' => 'TileSection_ContentTile', |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
public function getCMSFields() |
20
|
|
|
{ |
21
|
|
|
$fields = parent::getCMSFields(); |
22
|
|
|
|
23
|
|
|
$fields->push(DropdownField::create( |
24
|
|
|
'TilesPerRow', |
25
|
|
|
'Tiles Per Row', |
26
|
|
|
singleton('ContentBlock_TileSection') |
27
|
|
|
->dbObject('TilesPerRow') |
28
|
|
|
->enumValues() |
29
|
|
|
)); |
30
|
|
|
|
31
|
|
|
$fields->push(DropdownField::create( |
32
|
|
|
'TileTemplate', |
33
|
|
|
'Tile Template', |
34
|
|
|
$this->getAvailableTemplates() |
35
|
|
|
)); |
36
|
|
|
|
37
|
|
|
if ($this->getField('ID')) { |
38
|
|
|
$fields->push(GridField::create( |
39
|
|
|
'ContentTiles', |
40
|
|
|
'Content Tiles', |
41
|
|
|
$this->ContentTiles(), |
|
|
|
|
42
|
|
|
GridFieldConfig_RecordEditor::create() |
43
|
|
|
->addComponent(new GridFieldOrderableRows('Sort')) |
44
|
|
|
)); |
45
|
|
|
} else { |
46
|
|
|
$fields->push(LiteralField::create( |
47
|
|
|
'Unsaved', |
48
|
|
|
'<p class="message info">Please save first, to begin adding Tiles </p>' |
49
|
|
|
)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->extend('updateCMSFields', $fields); |
53
|
|
|
|
54
|
|
|
return $fields; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Gets available templates from the static configuration |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function getAvailableTemplates() |
63
|
|
|
{ |
64
|
|
|
$templates = Config::inst()->get('ContentBlock_TileSection', 'tile_templates'); |
65
|
|
|
|
66
|
|
|
$this->extend('updateAvailableTemplates', $templates); |
67
|
|
|
|
68
|
|
|
return (!empty($templates)) ? $templates : [] ; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Gets the block type for CMS display |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getBlockType() |
78
|
|
|
{ |
79
|
|
|
return 'Tile Section'; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.