diff --git a/_config/config.yml b/_config/config.yml new file mode 100644 index 0000000..f583213 --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,3 @@ +LeftAndMain: + extensions: + - BlogLeftMainExtension \ No newline at end of file diff --git a/code/BlogLeftMainExtension.php b/code/BlogLeftMainExtension.php new file mode 100644 index 0000000..32fa014 --- /dev/null +++ b/code/BlogLeftMainExtension.php @@ -0,0 +1,39 @@ +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); + } + } + } + } +} \ No newline at end of file