|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Blog\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Blog\Forms\GridField\GridFieldAddByDBField; |
|
6
|
|
|
use SilverStripe\Blog\Admin\GridFieldMergeAction; |
|
7
|
|
|
use SilverStripe\Blog\Model\CategorisationObject; |
|
8
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor; |
|
9
|
|
|
|
|
10
|
|
|
class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param int $itemsPerPage |
|
14
|
|
|
* @param array|SS_List $mergeRecords |
|
15
|
|
|
* @param string $parentType |
|
16
|
|
|
* @param string $parentMethod |
|
17
|
|
|
* @param string $childMethod |
|
18
|
|
|
*/ |
|
19
|
|
|
public function __construct($itemsPerPage = 15, $mergeRecords, $parentType, $parentMethod, $childMethod) |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct($itemsPerPage); |
|
22
|
|
|
|
|
23
|
|
|
$this->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton'); |
|
24
|
|
|
|
|
25
|
|
|
$this->addComponent( |
|
26
|
|
|
new GridFieldAddByDBField('buttons-before-left') |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
$this->addComponent( |
|
30
|
|
|
new GridFieldMergeAction($mergeRecords, $parentType, $parentMethod, $childMethod) |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var GridFieldDataColumns $columns |
|
35
|
|
|
*/ |
|
36
|
|
|
$columns = $this->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); |
|
37
|
|
|
|
|
38
|
|
|
$columns->setFieldFormatting( |
|
39
|
|
|
array( |
|
40
|
|
|
'BlogPostsCount' => function ($value, CategorisationObject $item) { |
|
41
|
|
|
return $item->BlogPosts()->Count(); |
|
42
|
|
|
} |
|
43
|
|
|
) |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
$this->changeColumnOrder(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Reorders GridField columns so that Actions is last. |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function changeColumnOrder() |
|
53
|
|
|
{ |
|
54
|
|
|
/** |
|
55
|
|
|
* @var GridFieldDataColumns $columns |
|
56
|
|
|
*/ |
|
57
|
|
|
$columns = $this->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); |
|
58
|
|
|
|
|
59
|
|
|
$columns->setDisplayFields( |
|
60
|
|
|
array( |
|
61
|
|
|
'Title' => 'Title', |
|
62
|
|
|
'BlogPostsCount' => 'Posts', |
|
63
|
|
|
'MergeAction' => 'MergeAction', |
|
64
|
|
|
'Actions' => 'Actions' |
|
65
|
|
|
) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|