silverstripe-blog/code/admin/GridFieldCategorisationConfig.php

54 lines
1.3 KiB
PHP
Raw Normal View History

2015-04-21 06:47:46 +02:00
<?php
class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor {
/**
* @param int $itemsPerPage
* @param array|SS_List $mergeRecords
* @param string $parentType
* @param string $parentMethod
* @param string $childMethod
*/
public function __construct($itemsPerPage = 15, $mergeRecords, $parentType, $parentMethod, $childMethod) {
parent::__construct($itemsPerPage);
2015-05-09 16:33:12 +02:00
$this->removeComponentsByType('GridFieldAddNewButton');
2015-04-21 06:47:46 +02:00
$this->addComponent(
2015-05-09 16:33:12 +02:00
new GridFieldAddByDBField('buttons-before-left')
2015-04-21 06:47:46 +02:00
);
$this->addComponent(
new GridFieldMergeAction($mergeRecords, $parentType, $parentMethod, $childMethod)
);
2015-05-09 16:33:12 +02:00
/**
* @var GridFieldDataColumns $columns
*/
2015-04-21 06:47:46 +02:00
$columns = $this->getComponentByType('GridFieldDataColumns');
$columns->setFieldFormatting(array(
2015-05-09 16:33:12 +02:00
'BlogPostsCount' => function ($value, CategorisationObject $item) {
2015-04-21 06:47:46 +02:00
return $item->BlogPosts()->Count();
}
));
$this->changeColumnOrder();
}
/**
* Reorders GridField columns so that Actions is last.
*/
protected function changeColumnOrder() {
/**
* @var GridFieldDataColumns $columns
*/
$columns = $this->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields(array(
'Title' => 'Title',
'BlogPostsCount' => 'Posts',
'MergeAction' => 'MergeAction',
'Actions' => 'Actions',
));
}
}