From 2e095c9cf437a78929ec6bef5ef2cc307f99f3b5 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Wed, 11 Jul 2018 16:08:08 -0400 Subject: [PATCH] Add url(), httpUrl() and editUrl() methods to Comment class. --- .../Fieldtype/FieldtypeComments/Comment.php | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/wire/modules/Fieldtype/FieldtypeComments/Comment.php b/wire/modules/Fieldtype/FieldtypeComments/Comment.php index 6ba65ada..ef5daac6 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/Comment.php +++ b/wire/modules/Fieldtype/FieldtypeComments/Comment.php @@ -172,7 +172,16 @@ class Comment extends WireData { } else if($key == 'children') { return $this->children(); - } + + } else if($key == 'url') { + return $this->url(); + + } else if($key == 'httpUrl' || $key == 'httpURL') { + return $this->httpUrl(); + + } else if($key == 'editUrl' || $key == 'editURL') { + return $this->editUrl(); + } return parent::get($key); } @@ -396,9 +405,39 @@ class Comment extends WireData { if(is_bool($quiet)) $this->quiet = $quiet; return $this->quiet; } - - + /** + * Return URL to view comment + * + * @param bool $http + * @return string + * + */ + public function url($http = false) { + $fragment = "#Comment$this->id"; + if(!$this->page || !$this->page->id) return $fragment; + return ($http ? $this->page->httpUrl() : $this->page->url) . $fragment; + } + + /** + * Return full http URL to view comment + * + * @return string + * + */ + public function httpUrl() { + return $this->url(true); + } + + /** + * Return URL to edit comment + * + */ + public function editUrl() { + if(!$this->page || !$this->page->id) return ''; + if(!$this->field) return ''; + return $this->page->editUrl() . "?field={$this->field->name}#CommentsAdminItem$this->id"; + } }