From 567c2236dbca534703327cdbdbc58b888303a6a4 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Tue, 5 Mar 2013 20:34:15 +1300 Subject: [PATCH] FIX Nicer fallback if Parent is not set correctly. --- code/dataobjects/Comment.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/code/dataobjects/Comment.php b/code/dataobjects/Comment.php index 70ceb93..b8f44ee 100755 --- a/code/dataobjects/Comment.php +++ b/code/dataobjects/Comment.php @@ -135,9 +135,11 @@ class Comment extends DataObject { * @return DataObject */ public function getParent() { - if(!$this->BaseClass) $this->BaseClass = "SiteTree"; + if(!$this->BaseClass) { + $this->BaseClass = "SiteTree"; + } - return DataObject::get_by_id($this->BaseClass, $this->ParentID); + return ($this->ParentID) ? DataObject::get_by_id($this->BaseClass, $this->ParentID) : null; } @@ -149,9 +151,9 @@ class Comment extends DataObject { public function getParentTitle(){ $parent = $this->getParent(); - return ($parent->Title) ? $parent->Title : $parent->ClassName . " #" . $parent->ID; + return ($parent && $parent->Title) ? $parent->Title : $parent->ClassName . " #" . $parent->ID; } - + /** * Comment-parent classnames obviousely vary, return the parent classname *