mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #302 from JorisDebonnet/patch-2
Sort BlogPosts in the CMS by PublishDate
This commit is contained in:
commit
6321417bc4
@ -71,10 +71,10 @@ class BlogFilter extends Lumberjack {
|
||||
$excluded = $this->owner->getExcludedSiteTreeClassNames();
|
||||
|
||||
if(!empty($excluded)) {
|
||||
$pages = SiteTree::get()->filter(array(
|
||||
$pages = BlogPost::get()->filter(array(
|
||||
'ParentID' => $this->owner->ID,
|
||||
'ClassName' => $excluded
|
||||
))->sort('"SiteTree"."Created" DESC');
|
||||
));
|
||||
|
||||
$gridField = new BlogFilter_GridField(
|
||||
'ChildPages',
|
||||
|
@ -84,9 +84,11 @@ class BlogPost extends Page {
|
||||
private static $allowed_children = array();
|
||||
|
||||
/**
|
||||
* The default sorting lists BlogPosts with an empty PublishDate at the top.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $default_sort = 'PublishDate DESC';
|
||||
private static $default_sort = '"PublishDate" IS NULL DESC, "PublishDate" DESC';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
@ -211,8 +213,10 @@ class BlogPost extends Page {
|
||||
_t('BlogPost.AdditionalCredits', 'Additional Credits'),
|
||||
null,
|
||||
1024
|
||||
)->setDescription(_t(
|
||||
'BlogPost.PublishDate_Description',
|
||||
'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.')
|
||||
);
|
||||
$authorNames->setDescription('If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.');
|
||||
|
||||
if(!$self->canEditAuthors()) {
|
||||
$authorField = $authorField->performDisabledTransformation();
|
||||
@ -221,6 +225,12 @@ class BlogPost extends Page {
|
||||
|
||||
$publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
|
||||
$publishDate->getDateField()->setConfig('showcalendar', true);
|
||||
if(!$self->PublishDate) {
|
||||
$publishDate->setDescription(_t(
|
||||
'BlogPost.PublishDate_Description',
|
||||
'Will be set to "now" if published without a value.')
|
||||
);
|
||||
}
|
||||
|
||||
// Get categories and tags
|
||||
$parent = $self->Parent();
|
||||
@ -365,8 +375,7 @@ class BlogPost extends Page {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Update the PublishDate to now, if being published for the first time, and the date hasn't
|
||||
* been set to the future.
|
||||
* Update the PublishDate to now if the BlogPost would otherwise be published without a date.
|
||||
*/
|
||||
public function onBeforePublish() {
|
||||
/**
|
||||
@ -374,7 +383,7 @@ class BlogPost extends Page {
|
||||
*/
|
||||
$publishDate = $this->dbObject('PublishDate');
|
||||
|
||||
if($publishDate->InPast() && !$this->isPublished()) {
|
||||
if(!$publishDate->getValue()) {
|
||||
$this->PublishDate = SS_Datetime::now()->getValue();
|
||||
$this->write();
|
||||
}
|
||||
@ -414,7 +423,7 @@ class BlogPost extends Page {
|
||||
if(!parent::canView($member)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var SS_Datetime $publishDate
|
||||
*/
|
||||
@ -625,10 +634,6 @@ class BlogPost extends Page {
|
||||
protected function onBeforeWrite() {
|
||||
parent::onBeforeWrite();
|
||||
|
||||
if(!$this->PublishDate) {
|
||||
$this->PublishDate = SS_Datetime::now()->getValue();
|
||||
}
|
||||
|
||||
if(!$this->exists() && ($member = Member::currentUser())) {
|
||||
$this->Authors()->add($member);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user