mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #234 from assertchris/fix-regressions
Fixed regressions
This commit is contained in:
commit
eb32e495cc
@ -114,6 +114,10 @@ class Blog extends Page implements PermissionProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!$fields) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$categories = GridField::create(
|
||||
'Categories',
|
||||
_t('Blog.Categories', 'Categories'),
|
||||
@ -128,6 +132,9 @@ class Blog extends Page implements PermissionProvider {
|
||||
GridFieldCategorisationConfig::create(15, $self->Tags(), 'BlogTag', 'Tags', 'BlogPosts')
|
||||
);
|
||||
|
||||
/**
|
||||
* @var FieldList $fields
|
||||
*/
|
||||
$fields->addFieldsToTab('Root.Categorisation', array(
|
||||
$categories,
|
||||
$tags
|
||||
@ -627,7 +634,12 @@ class Blog_Controller extends Page_Controller {
|
||||
* @return string
|
||||
*/
|
||||
public function index() {
|
||||
$this->blogPosts = $this->getBlogPosts();
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$this->blogPosts = $dataRecord->getBlogPosts();
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
@ -684,28 +696,35 @@ class Blog_Controller extends Page_Controller {
|
||||
/**
|
||||
* Renders an archive for a specified date. This can be by year or year/month.
|
||||
*
|
||||
* @return SS_HTTPResponse
|
||||
* @return null|SS_HTTPResponse
|
||||
*/
|
||||
public function archive() {
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$year = $this->getArchiveYear();
|
||||
$month = $this->getArchiveMonth();
|
||||
$day = $this->getArchiveDay();
|
||||
|
||||
if($this->request->param('Month') && !$month) {
|
||||
return $this->httpError(404, 'Not Found');
|
||||
$this->httpError(404, 'Not Found');
|
||||
}
|
||||
|
||||
if($month && $this->request->param('Day') && !$day) {
|
||||
return $this->httpError(404, 'Not Found');
|
||||
$this->httpError(404, 'Not Found');
|
||||
}
|
||||
|
||||
if($year) {
|
||||
$this->blogPosts = $this->getArchivedBlogPosts($year, $month, $day);
|
||||
$this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day);
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
return $this->httpError(404, 'Not Found');
|
||||
$this->httpError(404, 'Not Found');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -762,7 +781,7 @@ class Blog_Controller extends Page_Controller {
|
||||
/**
|
||||
* Renders the blog posts for a given tag.
|
||||
*
|
||||
* @return SS_HTTPResponse
|
||||
* @return null|SS_HTTPResponse
|
||||
*/
|
||||
public function tag() {
|
||||
$tag = $this->getCurrentTag();
|
||||
@ -772,7 +791,9 @@ class Blog_Controller extends Page_Controller {
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
return $this->httpError(404, 'Not Found');
|
||||
$this->httpError(404, 'Not Found');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -781,10 +802,15 @@ class Blog_Controller extends Page_Controller {
|
||||
* @return null|BlogTag
|
||||
*/
|
||||
public function getCurrentTag() {
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$tag = $this->request->param('Tag');
|
||||
|
||||
if($tag) {
|
||||
return $this->dataRecord->Tags()
|
||||
return $dataRecord->Tags()
|
||||
->filter('URLSegment', $tag)
|
||||
->first();
|
||||
}
|
||||
@ -795,17 +821,20 @@ class Blog_Controller extends Page_Controller {
|
||||
/**
|
||||
* Renders the blog posts for a given category.
|
||||
*
|
||||
* @return SS_HTTPResponse
|
||||
* @return null|SS_HTTPResponse
|
||||
*/
|
||||
public function category() {
|
||||
$category = $this->getCurrentCategory();
|
||||
|
||||
if($category) {
|
||||
$this->blogPosts = $category->BlogPosts();
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
return $this->httpError(404, 'Not Found');
|
||||
$this->httpError(404, 'Not Found');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -814,10 +843,15 @@ class Blog_Controller extends Page_Controller {
|
||||
* @return null|BlogCategory
|
||||
*/
|
||||
public function getCurrentCategory() {
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$category = $this->request->param('Category');
|
||||
|
||||
if($category) {
|
||||
return $this->dataRecord->Categories()
|
||||
return $dataRecord->Categories()
|
||||
->filter('URLSegment', $category)
|
||||
->first();
|
||||
}
|
||||
@ -835,7 +869,7 @@ class Blog_Controller extends Page_Controller {
|
||||
$filter = $this->getFilterDescription();
|
||||
|
||||
if($filter) {
|
||||
$title = sprintf('%s - $s', $title, $filter);
|
||||
$title = sprintf('%s - %s', $title, $filter);
|
||||
}
|
||||
|
||||
$this->extend('updateMetaTitle', $title);
|
||||
@ -934,6 +968,11 @@ class Blog_Controller extends Page_Controller {
|
||||
* @return PaginatedList
|
||||
*/
|
||||
public function PaginatedList() {
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$posts = new PaginatedList($this->blogPosts);
|
||||
|
||||
if($this->PostsPerPage > 0) {
|
||||
@ -941,7 +980,7 @@ class Blog_Controller extends Page_Controller {
|
||||
} else {
|
||||
$pageSize = 99999;
|
||||
|
||||
if($count = $this->getBlogPosts()->count()) {
|
||||
if($count = $dataRecord->getBlogPosts()->count()) {
|
||||
$pageSize = $count;
|
||||
}
|
||||
|
||||
@ -961,7 +1000,12 @@ class Blog_Controller extends Page_Controller {
|
||||
* @return string
|
||||
*/
|
||||
public function rss() {
|
||||
$rss = new RSSFeed($this->getBlogPosts(), $this->Link(), $this->MetaTitle, $this->MetaDescription);
|
||||
/**
|
||||
* @var Blog $dataRecord
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$rss = new RSSFeed($dataRecord->getBlogPosts(), $this->Link(), $this->MetaTitle, $this->MetaDescription);
|
||||
|
||||
$this->extend('updateRss', $rss);
|
||||
|
||||
|
@ -31,7 +31,7 @@ class BlogArchiveWidget extends Widget {
|
||||
*/
|
||||
private static $db = array(
|
||||
'NumberToDisplay' => 'Int',
|
||||
'ArchiveType' => 'Enum("Monthly,Yearly", "Monthly")',
|
||||
'ArchiveType' => 'Enum(\'Monthly,Yearly\', \'Monthly\')',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -55,12 +55,24 @@ class BlogArchiveWidget extends Widget {
|
||||
$self =& $this;
|
||||
|
||||
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
||||
$type = $self->dbObject('ArchiveType')->enumValues();
|
||||
if (!$fields) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Enum $archiveType
|
||||
*/
|
||||
$archiveType = $self->dbObject('ArchiveType');
|
||||
|
||||
$type = $archiveType->enumValues();
|
||||
|
||||
foreach($type as $k => $v) {
|
||||
$type[$k] = _t('BlogArchiveWidget.' . ucfirst(strtolower($v)), $v);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var FieldList $fields
|
||||
*/
|
||||
$fields->merge(array(
|
||||
DropdownField::create('BlogID', _t('BlogArchiveWidget.Blog', 'Blog'), Blog::get()->map()),
|
||||
DropdownField::create('ArchiveType', _t('BlogArchiveWidget.ArchiveType', 'ArchiveType'), $type),
|
||||
@ -80,9 +92,9 @@ class BlogArchiveWidget extends Widget {
|
||||
$query = $this->Blog()->getBlogPosts()->dataQuery();
|
||||
|
||||
if($this->ArchiveType == 'Yearly') {
|
||||
$query->groupBy('DATE_FORMAT(PublishDate, "%Y")');
|
||||
$query->groupBy('DATE_FORMAT(PublishDate, \'%Y\')');
|
||||
} else {
|
||||
$query->groupBy('DATE_FORMAT(PublishDate, "%Y-%M")');
|
||||
$query->groupBy('DATE_FORMAT(PublishDate, \'%Y-%M\')');
|
||||
}
|
||||
|
||||
$posts = $this->Blog()->getBlogPosts()->setDataQuery($query);
|
||||
|
@ -40,6 +40,13 @@ class BlogCategoriesWidget extends Widget {
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
$this->beforeUpdateCMSFields(function ($fields) {
|
||||
if (!$fields) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var FieldList $fields
|
||||
*/
|
||||
$fields->push(
|
||||
DropdownField::create('BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map())
|
||||
);
|
||||
|
@ -44,6 +44,13 @@ class BlogRecentPostsWidget extends Widget {
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
$this->beforeUpdateCMSFields(function ($fields) {
|
||||
if (!$fields) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var FieldList $fields
|
||||
*/
|
||||
$fields->merge(array(
|
||||
DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'Blog'), Blog::get()->map()),
|
||||
NumericField::create('NumberOfPosts', _t('BlogRecentPostsWidget.NumberOfPosts', 'Number of Posts'))
|
||||
|
@ -40,7 +40,16 @@ class BlogTagsWidget extends Widget {
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
$this->beforeUpdateCMSFields(function ($fields) {
|
||||
$fields->push(DropdownField::create('BlogID', _t('BlogTagsWidget.Blog', 'Blog'), Blog::get()->map()));
|
||||
if (!$fields) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var FieldList $fields
|
||||
*/
|
||||
$fields->push(
|
||||
DropdownField::create('BlogID', _t('BlogTagsWidget.Blog', 'Blog'), Blog::get()->map())
|
||||
);
|
||||
});
|
||||
|
||||
return parent::getCMSFields();
|
||||
|
Loading…
Reference in New Issue
Block a user