From e04be4cde43d0bc44fc010cd09dbaf431218351e Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 4 Nov 2015 17:20:16 +1300 Subject: [PATCH] BUG Fix crash if parent page isn't Blog type --- code/model/BlogPost.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index b7b126f..1b46817 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -602,14 +602,26 @@ class BlogPost extends Page { * @return ArrayList */ protected function getDynamicCredits() { - $items = new ArrayList(); + // Find best page to host user profiles + $parent = $this->Parent(); + if(! ($parent instanceof Blog) ) { + $parent = Blog::get()->first(); + } + // If there is no parent blog, return list undecorated + if(!$parent) { + $items = $this->Authors()->toArray(); + return new ArrayList($items); + } + + // Update all authors + $items = new ArrayList(); foreach($this->Authors() as $author) { - $items->push( - $author->customise(array( - 'URL' => $this->Parent->ProfileLink($author->URLSegment), - )) - ); + // Add link for each author + $author = $author->customise(array( + 'URL' => $parent->ProfileLink($author->URLSegment), + )); + $items->push($author); } return $items;