2015-09-10 11:30:10 +02:00
|
|
|
<?php
|
2016-09-09 09:00:05 +02:00
|
|
|
|
2017-06-16 06:07:09 +02:00
|
|
|
namespace Symbiote\GridFieldExtensions;
|
2016-11-29 18:20:15 +01:00
|
|
|
|
2016-09-09 09:00:05 +02:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
|
|
|
use SilverStripe\View\ArrayData;
|
|
|
|
|
2015-09-10 11:30:10 +02:00
|
|
|
/**
|
|
|
|
* Displays a link to an external source referenced 'external link'
|
|
|
|
*/
|
2016-12-21 03:34:58 +01:00
|
|
|
class GridFieldExternalLink extends GridFieldDataColumns
|
|
|
|
{
|
2015-09-10 11:30:10 +02:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
/**
|
|
|
|
* Add a column for the actions
|
|
|
|
*
|
|
|
|
* @param type $gridField
|
|
|
|
* @param array $columns
|
|
|
|
*/
|
|
|
|
public function augmentColumns($gridField, &$columns)
|
|
|
|
{
|
|
|
|
if (!in_array('Actions', $columns)) {
|
|
|
|
$columns[] = 'Actions';
|
|
|
|
}
|
|
|
|
}
|
2015-09-10 11:30:10 +02:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
/**
|
|
|
|
* Return any special attributes that will be used for FormField::create_tag()
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param DataObject $record
|
|
|
|
* @param string $columnName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumnAttributes($gridField, $record, $columnName)
|
|
|
|
{
|
|
|
|
return array('class' => 'col-buttons');
|
|
|
|
}
|
2015-09-10 11:30:10 +02:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
/**
|
|
|
|
* Add the title
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param string $columnName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumnMetadata($gridField, $columnName)
|
|
|
|
{
|
|
|
|
if ($columnName == 'Actions') {
|
|
|
|
return array('title' => '');
|
|
|
|
}
|
|
|
|
return array();
|
|
|
|
}
|
2015-09-10 11:30:10 +02:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
/**
|
|
|
|
* Which columns are handled by this component
|
|
|
|
*
|
|
|
|
* @param type $gridField
|
|
|
|
* @return type
|
|
|
|
*/
|
|
|
|
public function getColumnsHandled($gridField)
|
|
|
|
{
|
|
|
|
return array('Actions');
|
|
|
|
}
|
2015-09-10 11:30:10 +02:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
/**
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param DataObject $record
|
|
|
|
* @param string $columnName
|
|
|
|
*
|
|
|
|
* @return string - the HTML for the column
|
|
|
|
*/
|
|
|
|
public function getColumnContent($gridField, $record, $columnName)
|
|
|
|
{
|
|
|
|
$data = new ArrayData(array(
|
|
|
|
'Link' => $record->hasMethod('getExternalLink') ? $record->getExternalLink() : $record->ExternalLink,
|
|
|
|
'Text' => $record->hasMethod('getExternalLinkText') ? $record->getExternalLinkText() : 'External Link'
|
|
|
|
));
|
2015-09-10 11:30:10 +02:00
|
|
|
|
2016-12-21 03:34:58 +01:00
|
|
|
return $data->renderWith('GridFieldExternalLink');
|
|
|
|
}
|
2015-09-10 11:30:10 +02:00
|
|
|
}
|