|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* @author Christopher Darling (www.christopherdarling.co.uk) |
|
5
|
|
|
*/ |
|
6
|
|
|
class GridFieldSiteTree_PageHolderExtension extends DataExtension |
|
|
|
|
|
|
7
|
|
|
{ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Prevent children pages from showing up in the SiteTree TreeView |
|
11
|
|
|
**/ |
|
12
|
|
|
public function AllChildrenIncludingDeleted() |
|
13
|
|
|
{ |
|
14
|
|
|
return false; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/* |
|
18
|
|
|
* Create a GridField to display the pages. |
|
19
|
|
|
* |
|
20
|
|
|
* @see CMSMain::ListViewForm() heavily based on this code. |
|
21
|
|
|
* @param string $name |
|
22
|
|
|
* @param string $title |
|
|
|
|
|
|
23
|
|
|
* @param SS_List $dataList |
|
|
|
|
|
|
24
|
|
|
* @return GridField |
|
25
|
|
|
*/ |
|
26
|
|
|
public function getGridFieldSiteTreeField($name, $title=null, SS_List $dataList = null) |
|
27
|
|
|
{ |
|
28
|
|
|
$gf = GridField::create( |
|
29
|
|
|
$name, |
|
30
|
|
|
$title, |
|
31
|
|
|
$dataList, |
|
32
|
|
|
$config = GridFieldConfig::create() |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
$config->addComponents( |
|
36
|
|
|
new GridFieldSortableHeader(), |
|
37
|
|
|
$columns = new GridFieldDataColumns(), |
|
38
|
|
|
new GridFieldPaginator(15) |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
$fields = array( |
|
42
|
|
|
'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'), |
|
43
|
|
|
'singular_name' => _t('SiteTree.PAGETYPE'), |
|
44
|
|
|
'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'), |
|
45
|
|
|
); |
|
46
|
|
|
$columns->setDisplayFields($fields); |
|
47
|
|
|
$columns->setFieldCasting(array( |
|
48
|
|
|
'Created' => 'Datetime->Ago', |
|
49
|
|
|
'LastEdited' => 'Datetime->Ago', |
|
50
|
|
|
'getTreeTitle' => 'HTMLText' |
|
51
|
|
|
)); |
|
52
|
|
|
|
|
53
|
|
|
$config->getComponentByType('GridFieldSortableHeader')->setFieldSorting(array('getTreeTitle' => 'Title')); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
$controller = $this; |
|
56
|
|
|
$columns->setFieldFormatting(array( |
|
57
|
|
|
'getTreeTitle' => function ($value, &$item) use ($controller) { |
|
58
|
|
|
return '<a class="action-detail" href="' . singleton('CMSPageEditController')->Link('show') . '/' . $item->ID . '">' . $item->TreeTitle . '</a>'; |
|
59
|
|
|
} |
|
60
|
|
|
)); |
|
61
|
|
|
|
|
62
|
|
|
return $gf; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
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.