2012-05-11 09:44:39 +02:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\Forms\GridField;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\View\ArrayData;
|
|
|
|
use SilverStripe\View\SSViewer;
|
|
|
|
|
2012-05-11 09:44:39 +02:00
|
|
|
/**
|
|
|
|
* A button that allows a user to view readonly details of a record. This is
|
2013-05-20 12:18:07 +02:00
|
|
|
* disabled by default and intended for use in readonly {@link GridField}
|
|
|
|
* instances.
|
2012-05-11 09:44:39 +02:00
|
|
|
*/
|
|
|
|
class GridFieldViewButton implements GridField_ColumnProvider {
|
|
|
|
|
|
|
|
public function augmentColumns($field, &$cols) {
|
2016-08-23 04:32:26 +02:00
|
|
|
if(!in_array('Actions', $cols)) {
|
|
|
|
$cols[] = 'Actions';
|
|
|
|
}
|
2012-05-11 09:44:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumnsHandled($field) {
|
|
|
|
return array('Actions');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumnContent($field, $record, $col) {
|
2016-08-23 04:32:26 +02:00
|
|
|
if(!$record->canView()) {
|
|
|
|
return null;
|
2012-05-11 09:44:39 +02:00
|
|
|
}
|
2016-08-23 04:32:26 +02:00
|
|
|
$data = new ArrayData(array(
|
|
|
|
'Link' => Controller::join_links($field->Link('item'), $record->ID, 'view')
|
|
|
|
));
|
|
|
|
$template = SSViewer::get_templates_by_class($this, '', __CLASS__);
|
|
|
|
return $data->renderWith($template);
|
2012-05-11 09:44:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumnAttributes($field, $record, $col) {
|
2016-07-01 03:37:29 +02:00
|
|
|
return array('class' => 'grid-field__col-compact');
|
2012-05-11 09:44:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumnMetadata($gridField, $col) {
|
|
|
|
return array('title' => null);
|
|
|
|
}
|
|
|
|
}
|