mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Fixed regressions
This commit is contained in:
parent
e3f2036aaa
commit
a978b4a9a1
@ -100,7 +100,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
} else {
|
} else {
|
||||||
throw new UnexpectedValueException(
|
throw new UnexpectedValueException(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Invalid field (%s) on %s.',
|
'Invalid field (%s) on %s.',
|
||||||
$dbField,
|
$dbField,
|
||||||
$obj->ClassName
|
$obj->ClassName
|
||||||
)
|
)
|
||||||
|
@ -114,6 +114,10 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$fields) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$categories = GridField::create(
|
$categories = GridField::create(
|
||||||
'Categories',
|
'Categories',
|
||||||
_t('Blog.Categories', 'Categories'),
|
_t('Blog.Categories', 'Categories'),
|
||||||
@ -128,6 +132,9 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
GridFieldCategorisationConfig::create(15, $self->Tags(), 'BlogTag', 'Tags', 'BlogPosts')
|
GridFieldCategorisationConfig::create(15, $self->Tags(), 'BlogTag', 'Tags', 'BlogPosts')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var FieldList $fields
|
||||||
|
*/
|
||||||
$fields->addFieldsToTab('Root.Categorisation', array(
|
$fields->addFieldsToTab('Root.Categorisation', array(
|
||||||
$categories,
|
$categories,
|
||||||
$tags
|
$tags
|
||||||
@ -444,7 +451,7 @@ class Blog extends Page implements PermissionProvider {
|
|||||||
|
|
||||||
$stage = $query->getQueryParam('Versioned.stage');
|
$stage = $query->getQueryParam('Versioned.stage');
|
||||||
|
|
||||||
if ($stage) {
|
if($stage) {
|
||||||
$stage = '_' . $stage;
|
$stage = '_' . $stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,7 +634,12 @@ class Blog_Controller extends Page_Controller {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
$this->blogPosts = $this->getBlogPosts();
|
/**
|
||||||
|
* @var Blog $dataRecord
|
||||||
|
*/
|
||||||
|
$dataRecord = $this->dataRecord;
|
||||||
|
|
||||||
|
$this->blogPosts = $dataRecord->getBlogPosts();
|
||||||
|
|
||||||
return $this->render();
|
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.
|
* 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() {
|
public function archive() {
|
||||||
|
/**
|
||||||
|
* @var Blog $dataRecord
|
||||||
|
*/
|
||||||
|
$dataRecord = $this->dataRecord;
|
||||||
|
|
||||||
$year = $this->getArchiveYear();
|
$year = $this->getArchiveYear();
|
||||||
$month = $this->getArchiveMonth();
|
$month = $this->getArchiveMonth();
|
||||||
$day = $this->getArchiveDay();
|
$day = $this->getArchiveDay();
|
||||||
|
|
||||||
if($this->request->param('Month') && !$month) {
|
if($this->request->param('Month') && !$month) {
|
||||||
return $this->httpError(404, 'Not Found');
|
$this->httpError(404, 'Not Found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($month && $this->request->param('Day') && !$day) {
|
if($month && $this->request->param('Day') && !$day) {
|
||||||
return $this->httpError(404, 'Not Found');
|
$this->httpError(404, 'Not Found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($year) {
|
if($year) {
|
||||||
$this->blogPosts = $this->getArchivedBlogPosts($year, $month, $day);
|
$this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day);
|
||||||
|
|
||||||
return $this->render();
|
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.
|
* Renders the blog posts for a given tag.
|
||||||
*
|
*
|
||||||
* @return SS_HTTPResponse
|
* @return null|SS_HTTPResponse
|
||||||
*/
|
*/
|
||||||
public function tag() {
|
public function tag() {
|
||||||
$tag = $this->getCurrentTag();
|
$tag = $this->getCurrentTag();
|
||||||
@ -772,7 +791,9 @@ class Blog_Controller extends Page_Controller {
|
|||||||
return $this->render();
|
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
|
* @return null|BlogTag
|
||||||
*/
|
*/
|
||||||
public function getCurrentTag() {
|
public function getCurrentTag() {
|
||||||
|
/**
|
||||||
|
* @var Blog $dataRecord
|
||||||
|
*/
|
||||||
|
$dataRecord = $this->dataRecord;
|
||||||
|
|
||||||
$tag = $this->request->param('Tag');
|
$tag = $this->request->param('Tag');
|
||||||
|
|
||||||
if($tag) {
|
if($tag) {
|
||||||
return $this->dataRecord->Tags()
|
return $dataRecord->Tags()
|
||||||
->filter('URLSegment', $tag)
|
->filter('URLSegment', $tag)
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
@ -795,17 +821,20 @@ class Blog_Controller extends Page_Controller {
|
|||||||
/**
|
/**
|
||||||
* Renders the blog posts for a given category.
|
* Renders the blog posts for a given category.
|
||||||
*
|
*
|
||||||
* @return SS_HTTPResponse
|
* @return null|SS_HTTPResponse
|
||||||
*/
|
*/
|
||||||
public function category() {
|
public function category() {
|
||||||
$category = $this->getCurrentCategory();
|
$category = $this->getCurrentCategory();
|
||||||
|
|
||||||
if($category) {
|
if($category) {
|
||||||
$this->blogPosts = $category->BlogPosts();
|
$this->blogPosts = $category->BlogPosts();
|
||||||
|
|
||||||
return $this->render();
|
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
|
* @return null|BlogCategory
|
||||||
*/
|
*/
|
||||||
public function getCurrentCategory() {
|
public function getCurrentCategory() {
|
||||||
|
/**
|
||||||
|
* @var Blog $dataRecord
|
||||||
|
*/
|
||||||
|
$dataRecord = $this->dataRecord;
|
||||||
|
|
||||||
$category = $this->request->param('Category');
|
$category = $this->request->param('Category');
|
||||||
|
|
||||||
if($category) {
|
if($category) {
|
||||||
return $this->dataRecord->Categories()
|
return $dataRecord->Categories()
|
||||||
->filter('URLSegment', $category)
|
->filter('URLSegment', $category)
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
@ -835,7 +869,7 @@ class Blog_Controller extends Page_Controller {
|
|||||||
$filter = $this->getFilterDescription();
|
$filter = $this->getFilterDescription();
|
||||||
|
|
||||||
if($filter) {
|
if($filter) {
|
||||||
$title = sprintf('%s - $s', $title, $filter);
|
$title = sprintf('%s - %s', $title, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->extend('updateMetaTitle', $title);
|
$this->extend('updateMetaTitle', $title);
|
||||||
@ -934,6 +968,11 @@ class Blog_Controller extends Page_Controller {
|
|||||||
* @return PaginatedList
|
* @return PaginatedList
|
||||||
*/
|
*/
|
||||||
public function PaginatedList() {
|
public function PaginatedList() {
|
||||||
|
/**
|
||||||
|
* @var Blog $dataRecord
|
||||||
|
*/
|
||||||
|
$dataRecord = $this->dataRecord;
|
||||||
|
|
||||||
$posts = new PaginatedList($this->blogPosts);
|
$posts = new PaginatedList($this->blogPosts);
|
||||||
|
|
||||||
if($this->PostsPerPage > 0) {
|
if($this->PostsPerPage > 0) {
|
||||||
@ -941,7 +980,7 @@ class Blog_Controller extends Page_Controller {
|
|||||||
} else {
|
} else {
|
||||||
$pageSize = 99999;
|
$pageSize = 99999;
|
||||||
|
|
||||||
if($count = $this->getBlogPosts()->count()) {
|
if($count = $dataRecord->getBlogPosts()->count()) {
|
||||||
$pageSize = $count;
|
$pageSize = $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -961,7 +1000,12 @@ class Blog_Controller extends Page_Controller {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function rss() {
|
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);
|
$this->extend('updateRss', $rss);
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class BlogArchiveWidget extends Widget {
|
|||||||
*/
|
*/
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
'NumberToDisplay' => 'Int',
|
'NumberToDisplay' => 'Int',
|
||||||
'ArchiveType' => 'Enum("Monthly,Yearly", "Monthly")',
|
'ArchiveType' => 'Enum(\'Monthly,Yearly\', \'Monthly\')',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,15 +52,27 @@ class BlogArchiveWidget extends Widget {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields() {
|
||||||
$self = &$this;
|
$self =& $this;
|
||||||
|
|
||||||
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
$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) {
|
foreach($type as $k => $v) {
|
||||||
$type[$k] = _t('BlogArchiveWidget.' . ucfirst(strtolower($v)), $v);
|
$type[$k] = _t('BlogArchiveWidget.' . ucfirst(strtolower($v)), $v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var FieldList $fields
|
||||||
|
*/
|
||||||
$fields->merge(array(
|
$fields->merge(array(
|
||||||
DropdownField::create('BlogID', _t('BlogArchiveWidget.Blog', 'Blog'), Blog::get()->map()),
|
DropdownField::create('BlogID', _t('BlogArchiveWidget.Blog', 'Blog'), Blog::get()->map()),
|
||||||
DropdownField::create('ArchiveType', _t('BlogArchiveWidget.ArchiveType', 'ArchiveType'), $type),
|
DropdownField::create('ArchiveType', _t('BlogArchiveWidget.ArchiveType', 'ArchiveType'), $type),
|
||||||
@ -80,9 +92,9 @@ class BlogArchiveWidget extends Widget {
|
|||||||
$query = $this->Blog()->getBlogPosts()->dataQuery();
|
$query = $this->Blog()->getBlogPosts()->dataQuery();
|
||||||
|
|
||||||
if($this->ArchiveType == 'Yearly') {
|
if($this->ArchiveType == 'Yearly') {
|
||||||
$query->groupBy('DATE_FORMAT(PublishDate, "%Y")');
|
$query->groupBy('DATE_FORMAT(PublishDate, \'%Y\')');
|
||||||
} else {
|
} else {
|
||||||
$query->groupBy('DATE_FORMAT(PublishDate, "%Y-%M")');
|
$query->groupBy('DATE_FORMAT(PublishDate, \'%Y-%M\')');
|
||||||
}
|
}
|
||||||
|
|
||||||
$posts = $this->Blog()->getBlogPosts()->setDataQuery($query);
|
$posts = $this->Blog()->getBlogPosts()->setDataQuery($query);
|
||||||
|
@ -40,6 +40,13 @@ class BlogCategoriesWidget extends Widget {
|
|||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields() {
|
||||||
$this->beforeUpdateCMSFields(function ($fields) {
|
$this->beforeUpdateCMSFields(function ($fields) {
|
||||||
|
if (!$fields) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var FieldList $fields
|
||||||
|
*/
|
||||||
$fields->push(
|
$fields->push(
|
||||||
DropdownField::create('BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map())
|
DropdownField::create('BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map())
|
||||||
);
|
);
|
||||||
|
@ -44,6 +44,13 @@ class BlogRecentPostsWidget extends Widget {
|
|||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields() {
|
||||||
$this->beforeUpdateCMSFields(function ($fields) {
|
$this->beforeUpdateCMSFields(function ($fields) {
|
||||||
|
if (!$fields) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var FieldList $fields
|
||||||
|
*/
|
||||||
$fields->merge(array(
|
$fields->merge(array(
|
||||||
DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'Blog'), Blog::get()->map()),
|
DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'Blog'), Blog::get()->map()),
|
||||||
NumericField::create('NumberOfPosts', _t('BlogRecentPostsWidget.NumberOfPosts', 'Number of Posts'))
|
NumericField::create('NumberOfPosts', _t('BlogRecentPostsWidget.NumberOfPosts', 'Number of Posts'))
|
||||||
|
@ -40,7 +40,16 @@ class BlogTagsWidget extends Widget {
|
|||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields() {
|
||||||
$this->beforeUpdateCMSFields(function ($fields) {
|
$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();
|
return parent::getCMSFields();
|
||||||
|
Loading…
Reference in New Issue
Block a user