forked from jaedb/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
executable file
·108 lines (89 loc) · 2.93 KB
/
Module.php
File metadata and controls
executable file
·108 lines (89 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* @package modulemanager
*/
class Module extends DataObject {
// set module names
private static $singular_name = 'Generic';
private static $plural_name = 'Generic';
private static $description = 'Standard Module';
// set object parameters
private static $db = array(
'Title' => 'Varchar(255)',
'Content' => 'HTMLText',
'Position' => 'Varchar(255)'
);
private static $belongs_many_many = array(
'Pages' => 'SiteTree'
);
private static $summary_fields = array(
'Type' => 'Type',
'Title' => 'Title',
'Position' => 'Position',
'Pages.Count' => 'Number of pages'
);
private static $searchable_fields = array(
'Title',
'PositionID'
);
/**
* Identify this page component type
* Used in GridField for type identification
* @return array|integer|double|string|boolean
**/
public function Type(){
return $this->singular_name();
}
/**
* Convert our type into an escaped string for construcing classes
* @return string
**/
public function TypeEscaped(){
$type = $this->Type();
$type = str_replace(' ','_',$type);
$type = strtolower($type);
return $type;
}
/**
* Identify this page component type
* Used in GridField for type identification
* @return array|integer|double|string|boolean
**/
public function getDescription(){
return $this->stat('description');
}
/**
* Build the CMS fields for editing
* @return FieldList
**/
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName('Pages');
// required information
$fields->addFieldToTab('Root.Main', HiddenField::create('ModuleID', 'ModuleID', $this->ID));
$fields->addFieldToTab('Root.Main', LiteralField::create('html','<h3 style="margin-bottom: 5px;">'.$this->Type().'</h3>') );
$fields->addFieldToTab('Root.Main', LiteralField::create('html','<p><em>'.$this->getDescription().'</em></p><br />') );
$fields->addFieldToTab('Root.Main', TextField::create('Title', 'Title'));
$fields->addFieldToTab('Root.Main', DropdownField::create(
'Position',
'Position',
ModuleManager::get_positions_dropdown()
)->setEmptyString('Please select'));
$fields->addFieldToTab("Root.Main", TreeMultiselectField::create("Pages", "Shown on pages", "SiteTree"));
$fields->addFieldToTab('Root.Main', HTMLEditorField::create('Content', 'Content') );
return $fields;
}
/**
* Render the module-wrapper template
* @return HTMLText
**/
public function ModuleLayout(){
// try rendering with this module's own template
$output = $this->renderWith('Modules/'.$this->ClassName);
// no custom template, so use base template (Model.ss)
//if( !$output )
//$output = $this->renderWith('Module');
// TODO: Make this work. To make it work we actually need to properly check if we have a custom template for this class.
return $output;
}
}