silverstripe-framework/src/Forms/GridField/GridFieldViewButton.php
Luke Edwards 599a4420bf FIX Improve GridFieldViewButton to work with new Archive Admin (#8240)
* Add gridfield restore action, enable view button in action menu

* Abstract restore action and create test

* Use more appropriate canRestoreToDraft and isArchived, move translations

* Use Hierarchy to determine if a record should be restored to root

* Move restore action to versioned
2018-07-13 10:45:13 +12:00

84 lines
2.0 KiB
PHP

<?php
namespace SilverStripe\Forms\GridField;
use SilverStripe\Control\Controller;
use SilverStripe\View\ArrayData;
use SilverStripe\View\SSViewer;
/**
* A button that allows a user to view readonly details of a record. This is
* disabled by default and intended for use in readonly {@link GridField}
* instances.
*/
class GridFieldViewButton implements GridField_ColumnProvider, GridField_ActionMenuLink
{
/**
* @inheritdoc
*/
public function getTitle($gridField, $record, $columnName)
{
return _t(__CLASS__ . '.VIEW', "View");
}
/**
* @inheritdoc
*/
public function getGroup($gridField, $record, $columnName)
{
return GridField_ActionMenuItem::DEFAULT_GROUP;
}
/**
* @inheritdoc
*/
public function getExtraData($gridField, $record, $columnName)
{
return [
"classNames" => "font-icon-eye action-detail view-link"
];
}
/**
* @inheritdoc
*/
public function getUrl($gridField, $record, $columnName)
{
return Controller::join_links($gridField->Link('item'), $record->ID, 'view');
}
public function augmentColumns($field, &$columns)
{
if (!in_array('Actions', $columns)) {
$columns[] = 'Actions';
}
}
public function getColumnsHandled($field)
{
return ['Actions'];
}
public function getColumnContent($field, $record, $col)
{
if (!$record->canView()) {
return null;
}
$data = new ArrayData([
'Link' => Controller::join_links($field->Link('item'), $record->ID, 'view')
]);
$template = SSViewer::get_templates_by_class($this, '', __CLASS__);
return $data->renderWith($template);
}
public function getColumnAttributes($field, $record, $col)
{
return ['class' => 'grid-field__col-compact'];
}
public function getColumnMetadata($gridField, $col)
{
return ['title' => null];
}
}