1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Models a Content Tile for a {@link ContentBlock_TileSection} |
4
|
|
|
* |
5
|
|
|
* @since 1.0.0 |
6
|
|
|
*/ |
7
|
|
|
class TileSection_ContentTile extends DataObject |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
private static $singular_name = 'Content Tile'; |
|
|
|
|
10
|
|
|
private static $plural_name = 'Content Tiles'; |
|
|
|
|
11
|
|
|
|
12
|
|
|
private static $casting = [ |
|
|
|
|
13
|
|
|
'RenderTile' => 'HTMLText' |
14
|
|
|
]; |
15
|
|
|
|
16
|
|
|
private static $db = [ |
|
|
|
|
17
|
|
|
'Title' => 'Text', |
18
|
|
|
'Caption' => 'Text', |
19
|
|
|
'Sort' => 'Int' |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
private static $has_one = [ |
|
|
|
|
23
|
|
|
'Image' => 'Image', |
24
|
|
|
'Link' => 'Link', |
25
|
|
|
'Parent' => 'ContentBlock_TileSection', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
private static $default_sort = 'Sort ASC'; |
|
|
|
|
29
|
|
|
|
30
|
|
|
public function getCMSFields() |
31
|
|
|
{ |
32
|
|
|
$fields = FieldList::create([ |
33
|
|
|
TextField::create('Title'), |
34
|
|
|
TextareaField::create('Caption'), |
35
|
|
|
UploadField::create('Image'), |
36
|
|
|
LinkField::create('LinkID'), |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
$this->extend('updateCMSFields', $fields); |
40
|
|
|
|
41
|
|
|
return $fields; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return RequiredFields |
46
|
|
|
*/ |
47
|
|
|
public function getCMSValidator() |
48
|
|
|
{ |
49
|
|
|
return RequiredFields::create(array( |
50
|
|
|
'Title', |
51
|
|
|
'Image', |
52
|
|
|
'LinkID', |
53
|
|
|
)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Gets the chosen template name from the parent {@link ContentBlock_TileSection} |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function getTemplateName() |
62
|
|
|
{ |
63
|
|
|
if ($parent = $this->getComponent('Parent')) { |
64
|
|
|
return $parent->getField('TileTemplate'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Renders the Tile into the parent {@link ContentBlock_TileSection}'s chosen template |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function RenderTile() |
74
|
|
|
{ |
75
|
|
|
if ($template = $this->getTemplateName()) { |
76
|
|
|
return $this->renderWith($template); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Gets the configured classes for a row |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function TileClasses() |
86
|
|
|
{ |
87
|
|
|
$classesArray = Config::inst()->get('ContentBlock_TileSection', 'tile_classes'); |
88
|
|
|
|
89
|
|
|
$this->extend('updateTileClasses', $classes); |
90
|
|
|
|
91
|
|
|
return (!empty($classesArray)) ? implode(' ', $classesArray) : '' ; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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.