-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModuleSiteTreeExtension.php
More file actions
61 lines (43 loc) · 1.48 KB
/
ModuleSiteTreeExtension.php
File metadata and controls
61 lines (43 loc) · 1.48 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
<?php
/**
* @package modulemanager
*/
class ModuleSiteTreeExtension extends DataExtension {
// set object parameters
public static $db = array();
// set object parameters
public static $belongs_many_many = array(
'Modules' => 'Module'
);
// create cms fields
public function updateCMSFields(FieldList $fields) {
// create gridfield management for the many_many relationship
$gridFieldConfig = GridFieldConfig_RelationEditor::create();
// create the gridfield itself
$gridField = new GridField("Modules", "Modules", $this->PageModules(), $gridFieldConfig);
// add to fields
$fields->addFieldToTab("Root.Modules", $gridField);
return $fields;
}
// build list of all Modules attached to this page
public function PageModules(){
$modules = $this->owner->getManyManyComponents('Modules');
return $modules;
}
// return all modules of the specified module area
// called in template with $ModuleArea(module-alias)
function ModuleArea($alias){
// create container for output code
$output = '';
// get the module area as an object
$position = ModulePosition::get()->filter('Alias', $alias)->First();
// get this page's module list
$modules = $this->PageModules();
// store them in a template array (for template loop)
$items = array(
'Position' => $position,
'Items' => $modules
);
return $this->owner->customise($items)->renderWith('ModuleHolder');
}
}