diff --git a/code/Report.php b/code/Report.php index 56e8561e..7affdd0f 100644 --- a/code/Report.php +++ b/code/Report.php @@ -219,7 +219,7 @@ class SS_Report extends ViewableData { */ public function getCMSFields() { $fields = new FieldList(); - + if($description = $this->description()) { $fields->push(new LiteralField('ReportDescription', "

" . $description . "

")); } @@ -288,8 +288,20 @@ class SS_Report extends ViewableData { if(isset($info['casting'])) $fieldCasting[$source] = $info['casting']; if(isset($info['link']) && $info['link']) { - $link = singleton('CMSPageEditController')->Link('show'); - $fieldFormatting[$source] = '$value'; + $fieldFormatting[$source] = function($value, $item) { + $title = Convert::raw2xml($value); + + // If this item is previewable, decorate with link + if ($item instanceof CMSPreviewable) { + return sprintf( + '%s', + $item->CMSEditLink(), $title, $title + ); + } + + // Fall back to basic title + return $title; + }; } $displayFields[$source] = isset($info['title']) ? $info['title'] : $source; diff --git a/tests/ReportTest.php b/tests/ReportTest.php index 9193e604..c58237c1 100644 --- a/tests/ReportTest.php +++ b/tests/ReportTest.php @@ -78,6 +78,42 @@ class ReportTest extends SapphireTest { $this->logInWithPermission('ADMIN'); $this->assertTrue($report->canView()); } + + public function testColumnLink() { + $report = new ReportTest_FakeTest(); + /** @var GridField $gridField */ + $gridField = $report->getReportField(); + /** @var GridFieldDataColumns $columns */ + $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); + + $page = new ReportTest_FakeObject(); + $page->Title = 'My Object'; + $page->ID = 959547; + + $titleContent = $columns->getColumnContent($gridField, $page, 'Title'); + $this->assertEquals('My Object', $titleContent); + } +} + +class ReportTest_FakeObject extends DataObject implements CMSPreviewable, TestOnly { + + private static $db = array( + 'Title' => 'Varchar' + ); + + /** + * @return String Absolute URL to the end-user view for this record. + * Example: http://mysite.com/my-record + */ + public function Link() + { + return Controller::join_links('dummy-link', $this->ID); + } + + public function CMSEditLink() + { + return Controller::join_links('dummy-edit-link', $this->ID); + } } /** @@ -91,7 +127,8 @@ class ReportTest_FakeTest extends SS_Report implements TestOnly { public function columns() { return array( "Title" => array( - "title" => "Page Title" + "title" => "Page Title", + "link" => true, ) ); } @@ -133,7 +170,7 @@ class ReportTest_FakeTest2 extends SS_Report implements TestOnly { * @subpackage tests */ abstract class ReportTest_FakeTest_Abstract extends SS_Report implements TestOnly { - + public function title() { return 'Report title Abstract'; }