1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Models a Content Block - a base class for different types of Content Blocks |
5
|
|
|
* |
6
|
|
|
* @since 1.0.0 |
7
|
|
|
*/ |
8
|
|
|
class ContentBlock extends DataObject |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
private static $casting = [ |
|
|
|
|
12
|
|
|
'RenderBlock' => 'HTMLText' |
13
|
|
|
]; |
14
|
|
|
|
15
|
|
|
private static $db = [ |
|
|
|
|
16
|
|
|
'Sort' => 'Int', |
17
|
|
|
'Title' => 'Text', |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
private static $has_one = [ |
|
|
|
|
21
|
|
|
'ParentPage' => 'SiteTree', |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
private static $default_sort = 'Sort ASC'; |
|
|
|
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
public function getCMSFields() |
28
|
|
|
{ |
29
|
|
|
return FieldList::create([ |
30
|
|
|
TextField::create('Title') |
31
|
|
|
->setDescription('For CMS Identification') |
32
|
|
|
]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return RequiredFields |
37
|
|
|
*/ |
38
|
|
|
public function getCMSValidator() |
39
|
|
|
{ |
40
|
|
|
return RequiredFields::create([ |
41
|
|
|
'Title' |
42
|
|
|
]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function onBeforeWrite() |
46
|
|
|
{ |
47
|
|
|
parent::onBeforeWrite(); |
48
|
|
|
|
49
|
|
|
if (!$this->getField('Title')) { |
50
|
|
|
$this->Title = sprintf('New %s', $this->getBlockType()); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getTemplateName() |
58
|
|
|
{ |
59
|
|
|
$template = $this->getField('ClassName'); |
60
|
|
|
$this->extend('updateTemplateName', $template); |
61
|
|
|
return $template; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Renders the block for template |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function RenderBlock() |
70
|
|
|
{ |
71
|
|
|
if (Config::inst()->get('ContentBlock', 'include_bootstrap')) { |
72
|
|
|
Requirements::javascript(CONTENTBLOCKS_DIR . '/javascript/lib/bootstrap.min.js'); |
73
|
|
|
Requirements::css(CONTENTBLOCKS_DIR . '/css/lib/bootstrap.min.css'); |
74
|
|
|
} |
75
|
|
|
return $this->renderWith($this->getTemplateName()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Gets the block type for CMS display |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function getBlockType() |
84
|
|
|
{ |
85
|
|
|
return 'Content Block'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
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.