2015-04-21 06:47:46 +02:00
|
|
|
<?php
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
namespace SilverStripe\Blog\Admin;
|
|
|
|
|
2016-12-16 05:10:38 +01:00
|
|
|
use SilverStripe\Blog\Forms\GridField\GridFieldAddByDBField;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Blog\Model\CategorisationObject;
|
2018-04-06 00:21:26 +02:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
2018-01-29 04:13:19 +01:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
2018-04-06 00:21:26 +02:00
|
|
|
use SilverStripe\ORM\SS_List;
|
2016-12-15 04:41:49 +01:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param int $itemsPerPage
|
|
|
|
* @param array|SS_List $mergeRecords
|
|
|
|
* @param string $parentType
|
|
|
|
* @param string $parentMethod
|
|
|
|
* @param string $childMethod
|
|
|
|
*/
|
2018-01-29 03:59:46 +01:00
|
|
|
public function __construct($itemsPerPage, $mergeRecords, $parentType, $parentMethod, $childMethod)
|
2015-11-21 07:17:29 +01:00
|
|
|
{
|
|
|
|
parent::__construct($itemsPerPage);
|
|
|
|
|
2018-04-06 00:21:26 +02:00
|
|
|
$this->removeComponentsByType(GridFieldAddNewButton::class);
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
$this->addComponent(
|
2017-09-14 01:49:27 +02:00
|
|
|
GridFieldAddByDBField::create('buttons-before-left')
|
2015-11-21 07:17:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->addComponent(
|
2017-09-14 01:49:27 +02:00
|
|
|
GridFieldMergeAction::create($mergeRecords, $parentType, $parentMethod, $childMethod)
|
2015-11-21 07:17:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var GridFieldDataColumns $columns
|
|
|
|
*/
|
2018-04-06 00:21:26 +02:00
|
|
|
$columns = $this->getComponentByType(GridFieldDataColumns::class);
|
2015-11-21 07:17:29 +01:00
|
|
|
|
2016-12-16 05:10:38 +01:00
|
|
|
$columns->setFieldFormatting(
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2016-12-16 05:10:38 +01:00
|
|
|
'BlogPostsCount' => function ($value, CategorisationObject $item) {
|
|
|
|
return $item->BlogPosts()->Count();
|
|
|
|
}
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2016-12-16 05:10:38 +01:00
|
|
|
);
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
$this->changeColumnOrder();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reorders GridField columns so that Actions is last.
|
|
|
|
*/
|
|
|
|
protected function changeColumnOrder()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var GridFieldDataColumns $columns
|
|
|
|
*/
|
2018-04-06 00:21:26 +02:00
|
|
|
$columns = $this->getComponentByType(GridFieldDataColumns::class);
|
2015-11-21 07:17:29 +01:00
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
$columns->setDisplayFields(
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2018-01-16 18:17:41 +01:00
|
|
|
'Title' => _t(__CLASS__ . '.Title', 'Title'),
|
|
|
|
'BlogPostsCount' => _t(__CLASS__ . '.Posts', 'Posts'),
|
2016-12-15 04:41:49 +01:00
|
|
|
'MergeAction' => 'MergeAction',
|
|
|
|
'Actions' => 'Actions'
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2016-12-15 04:41:49 +01:00
|
|
|
);
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|
|
|
|
}
|