Skip to content

Commit

Permalink
Merge pull request #265 from tractorcow/pulls/fix-parent
Browse files Browse the repository at this point in the history
BUG Fix BlogPost crashing when created under a non-blog parent
  • Loading branch information
assertchris committed Jun 4, 2015
2 parents 1430018 + 0941b4e commit 0522b1b
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 0522b1b

Please sign in to comment.