Merge pull request #265 from tractorcow/pulls/fix-parent

BUG Fix BlogPost crashing when created under a non-blog parent
This commit is contained in:
Christopher Pitt 2015-06-04 13:55:34 +12:00
commit 0522b1b7db

View File

@ -222,13 +222,22 @@ class BlogPost extends Page {
$publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date')); $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
$publishDate->getDateField()->setConfig('showcalendar', true); $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( $options = BlogAdminSidebar::create(
$publishDate, $publishDate,
$urlSegment, $urlSegment,
TagField::create( TagField::create(
'Categories', 'Categories',
_t('BlogPost.Categories', 'Categories'), _t('BlogPost.Categories', 'Categories'),
$self->Parent()->Categories(), $categories,
$self->Categories() $self->Categories()
) )
->setCanCreate($self->canCreateCategories()) ->setCanCreate($self->canCreateCategories())
@ -236,7 +245,7 @@ class BlogPost extends Page {
TagField::create( TagField::create(
'Tags', 'Tags',
_t('BlogPost.Tags', 'Tags'), _t('BlogPost.Tags', 'Tags'),
$self->Parent()->Tags(), $tags,
$self->Tags() $self->Tags()
) )
->setCanCreate($self->canCreateTags()) ->setCanCreate($self->canCreateTags())