Merge branch '3'

This commit is contained in:
Daniel Hensby 2016-11-10 11:53:48 +00:00
commit 537f4da88f
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
2 changed files with 62 additions and 10 deletions

View File

@ -23,6 +23,7 @@ use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Core\Convert;
use SilverStripe\View\ViewableData;
use ReflectionClass;
use SilverStripe\Admin\CMSPreviewable ;
/**
* Base "abstract" class creating reports on your data.
@ -369,12 +370,15 @@ class Report extends ViewableData
if (isset($info['link']) && $info['link']) {
$fieldFormatting[$source] = function($value, $item) {
if ($item instanceof CMSPreviewable) {
/** @var CMSPreviewable $item */
return sprintf(
'<a class="grid-field__link-block" href="%s">%s</a>',
Convert::raw2att($item->CMSEditLink()),
Convert::raw2xml($value)
);
}
return $value;
};
}

View File

@ -1,10 +1,13 @@
<?php
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\Reports\Report;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Session;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Admin\CMSPreviewable ;
/**
@ -89,6 +92,50 @@ 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('<a href="dummy-edit-link/959547" title="My Object">My Object</a>', $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);
}
public function PreviewLink($action = null) {
return false;
}
public function getMimeType() {
return 'text/html';
}
}
/**
@ -105,7 +152,8 @@ class ReportTest_FakeTest extends Report implements TestOnly
{
return array(
"Title" => array(
"title" => "Page Title"
"title" => "Page Title",
"link" => true,
)
);
}