Skip to content

Commit

Permalink
BUG Fix BlogPost crashing when created under a non-blog parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Jun 4, 2015
1 parent 1430018 commit 0941b4e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions code/model/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,30 @@ public function getCMSFields() {
$publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
$publishDate->getDateField()->setConfig('showcalendar', true);

// Get categories and tags
$parent = $self->Parent();
$categories = $parent instanceof Blog
? $parent->Categories()
: BlogCategory::get();
$tags = $parent instanceof Blog
? $parent->Tags()
: BlogTag::get();

$options = BlogAdminSidebar::create(
$publishDate,
$urlSegment,
TagField::create(
'Categories',
_t('BlogPost.Categories', 'Categories'),
$self->Parent()->Categories(),
$categories,
$self->Categories()
)
->setCanCreate($self->canCreateCategories())
->setShouldLazyLoad(true),
TagField::create(
'Tags',
_t('BlogPost.Tags', 'Tags'),
$self->Parent()->Tags(),
$tags,
$self->Tags()
)
->setCanCreate($self->canCreateTags())
Expand Down

0 comments on commit 0941b4e

Please sign in to comment.