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