mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
NEW Show "post" date and author in CMS list view for blog entries
This commit is contained in:
parent
8cfabfc3d8
commit
0aef171108
3
_config/config.yml
Normal file
3
_config/config.yml
Normal file
@ -0,0 +1,3 @@
|
||||
LeftAndMain:
|
||||
extensions:
|
||||
- BlogLeftMainExtension
|
39
code/BlogLeftMainExtension.php
Normal file
39
code/BlogLeftMainExtension.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Influences the page list behaviour of blog entries in the CMS.
|
||||
* Adds author and "post date" fields.
|
||||
*/
|
||||
class BlogLeftMainExtension extends Extension {
|
||||
function updateListView($listView) {
|
||||
$parentId = $listView->getController()->getRequest()->requestVar('ParentID');
|
||||
$parent = ($parentId) ? Page::get()->byId($parentId) : new Page();
|
||||
|
||||
// Only apply logic for this page type
|
||||
if($parent && $parent instanceof BlogHolder) {
|
||||
$gridField = $listView->Fields()->dataFieldByName('Page');
|
||||
if($gridField) {
|
||||
// Sort by post date
|
||||
$list = $gridField->getList();
|
||||
$list = $list->leftJoin('BlogEntry', '"BlogEntry"."ID" = "SiteTree"."ID"');
|
||||
$gridField->setList($list->sort('Date', 'DESC'));
|
||||
|
||||
// Change columns
|
||||
$cols = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
|
||||
if($cols) {
|
||||
$fields = $cols->getDisplayFields($gridField);
|
||||
$castings = $cols->getFieldCasting($gridField);
|
||||
|
||||
// Add author to columns
|
||||
$fields['Author'] = _t("BlogEntry.AU", "Author");
|
||||
// Add post date and remove duplicate "created" date
|
||||
$fields['Date'] = _t("BlogEntry.DT", "Date");
|
||||
$castings['Date'] = 'SS_Datetime->Ago';
|
||||
if(isset($fields['Created'])) unset($fields['Created']);
|
||||
|
||||
$cols->setDisplayFields($fields);
|
||||
$cols->setFieldCasting($castings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user