From 87477a1e01d03ebee7eb71c352b3da47da73a9f2 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 12 Jul 2016 15:43:48 +1200 Subject: [PATCH 1/2] BUG Fix incorrect url manipulation Fixes https://github.com/silverstripe/silverstripe-cms/issues/1183 --- code/Report.php | 88 +++++++++++++++++++++++++------------------- tests/ReportTest.php | 43 +++++++++++++++++++++- 2 files changed, 91 insertions(+), 40 deletions(-) diff --git a/code/Report.php b/code/Report.php index 79995047..f77de15d 100644 --- a/code/Report.php +++ b/code/Report.php @@ -1,32 +1,32 @@ title; } - + /** * Allows access to title as a property - * + * * @return string */ public function getTitle() { return $this->title(); } - + /** * Return the description of this report. - * + * * You have two ways of specifying the description: - * - overriding description(), which lets you support i18n + * - overriding description(), which lets you support i18n * - defining the $description property */ public function description() { return $this->description; } - + /** * Return the {@link SQLQuery} that provides your report data. */ @@ -116,7 +116,7 @@ class SS_Report extends ViewableData { user_error("Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()", E_USER_ERROR); } } - + /** * Return a SS_List records for this report. */ @@ -223,11 +223,11 @@ class SS_Report extends ViewableData { if($title = $this->title()) { $fields->push(new LiteralField('ReportTitle', "

{$title}

")); } - + if($description = $this->description()) { $fields->push(new LiteralField('ReportDescription', "

" . $description . "

")); } - + // Add search fields is available if($this->hasMethod('parameterFields') && $parameterFields = $this->parameterFields()) { foreach($parameterFields as $field) { @@ -240,25 +240,25 @@ class SS_Report extends ViewableData { // Add a search button $fields->push(new FormAction('updatereport', _t('GridField.Filter'))); } - + $fields->push($this->getReportField()); $this->extend('updateCMSFields', $fields); - + return $fields; } - + public function getCMSActions() { // getCMSActions() can be extended with updateCMSActions() on a extension $actions = new FieldList(); $this->extend('updateCMSActions', $actions); return $actions; } - + /** * Return a field, such as a {@link GridField} that is * used to show and manipulate data relating to this report. - * + * * Generally, you should override {@link columns()} and {@link records()} to make your report, * but if they aren't sufficiently flexible, then you can override this method. * @@ -287,14 +287,26 @@ class SS_Report extends ViewableData { // Parse the column information foreach($this->columns() as $source => $info) { if(is_string($info)) $info = array('title' => $info); - + if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting']; if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting']; 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; @@ -305,7 +317,7 @@ class SS_Report extends ViewableData { return $gridField; } - + /** * @param Member $member * @return boolean @@ -347,7 +359,7 @@ class SS_Report extends ViewableData { } return null; } - + /** * Return the name of this report, which @@ -365,17 +377,17 @@ class SS_Report extends ViewableData { /** * SS_ReportWrapper is a base class for creating report wappers. - * + * * Wrappers encapsulate an existing report to alter their behaviour - they are implementations of * the standard GoF decorator pattern. - * + * * This base class ensure that, by default, wrappers behave in the same way as the report that is * being wrapped. You should override any methods that need to behave differently in your subclass * of SS_ReportWrapper. - * + * * It also makes calls to 2 empty methods that you can override {@link beforeQuery()} and * {@link afterQuery()} - * + * * @package reports */ abstract class SS_ReportWrapper extends SS_Report { @@ -450,11 +462,11 @@ abstract class SS_ReportWrapper extends SS_Report { public function title() { return $this->baseReport->title(); } - + public function group() { return $this->baseReport->hasMethod('group') ? $this->baseReport->group() : 'Group'; } - + public function sort() { return $this->baseReport->hasMethod('sort') ? $this->baseReport->sort() : 0; } @@ -465,5 +477,5 @@ abstract class SS_ReportWrapper extends SS_Report { public function canView($member = null) { return $this->baseReport->canView($member); - } + } } diff --git a/tests/ReportTest.php b/tests/ReportTest.php index 2df30585..c58237c1 100644 --- a/tests/ReportTest.php +++ b/tests/ReportTest.php @@ -6,6 +6,8 @@ */ class ReportTest extends SapphireTest { + protected $usesDatabase = true; + public function testGetReports() { $reports = SS_Report::get_reports(); $this->assertNotNull($reports, "Reports returned"); @@ -76,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); + } } /** @@ -89,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, ) ); } @@ -131,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'; } From 6c1f17da916e4d30bc7b28b05f3535ac6e902551 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 28 Jul 2016 14:34:38 +1200 Subject: [PATCH 2/2] Remove obsolete alias --- composer.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/composer.json b/composer.json index 90d5a3f9..060ce26c 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,6 @@ "php": ">=5.3.3,<7", "silverstripe/framework": "~3.3" }, - "extra": { - "branch-alias": { - "3.x-dev": "3.4.x-dev" - } - }, "require-dev": { "phpunit/PHPUnit": "~3.7" }