diff --git a/code/forms/gridfield/GridFieldAddByDBField.php b/code/forms/gridfield/GridFieldAddByDBField.php index 4a76437..706abd8 100644 --- a/code/forms/gridfield/GridFieldAddByDBField.php +++ b/code/forms/gridfield/GridFieldAddByDBField.php @@ -100,7 +100,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP } else { throw new UnexpectedValueException( sprintf( - 'Invalid field (%s) on %s.', + 'Invalid field (%s) on %s.', $dbField, $obj->ClassName ) diff --git a/code/model/Blog.php b/code/model/Blog.php index 7699222..10aca67 100644 --- a/code/model/Blog.php +++ b/code/model/Blog.php @@ -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 @@ -444,7 +451,7 @@ class Blog extends Page implements PermissionProvider { $stage = $query->getQueryParam('Versioned.stage'); - if ($stage) { + if($stage) { $stage = '_' . $stage; } @@ -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); diff --git a/code/widgets/BlogArchiveWidget.php b/code/widgets/BlogArchiveWidget.php index c7a5e78..60cb56c 100644 --- a/code/widgets/BlogArchiveWidget.php +++ b/code/widgets/BlogArchiveWidget.php @@ -31,7 +31,7 @@ class BlogArchiveWidget extends Widget { */ private static $db = array( 'NumberToDisplay' => 'Int', - 'ArchiveType' => 'Enum("Monthly,Yearly", "Monthly")', + 'ArchiveType' => 'Enum(\'Monthly,Yearly\', \'Monthly\')', ); /** @@ -52,15 +52,27 @@ class BlogArchiveWidget extends Widget { * {@inheritdoc} */ public function getCMSFields() { - $self = &$this; + $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); diff --git a/code/widgets/BlogCategoriesWidget.php b/code/widgets/BlogCategoriesWidget.php index ce07580..bbfef9c 100644 --- a/code/widgets/BlogCategoriesWidget.php +++ b/code/widgets/BlogCategoriesWidget.php @@ -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()) ); diff --git a/code/widgets/BlogRecentPostsWidget.php b/code/widgets/BlogRecentPostsWidget.php index 7886d16..c773e2b 100644 --- a/code/widgets/BlogRecentPostsWidget.php +++ b/code/widgets/BlogRecentPostsWidget.php @@ -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')) diff --git a/code/widgets/BlogTagsWidget.php b/code/widgets/BlogTagsWidget.php index 5efed18..62a849a 100644 --- a/code/widgets/BlogTagsWidget.php +++ b/code/widgets/BlogTagsWidget.php @@ -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();