-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allowing to refer to external links from a modeladmin
- Loading branch information
Peter Thaleikis
committed
Sep 10, 2015
1 parent
b4a0c96
commit 8a9e075
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Displays a link to an external source referenced 'external link' | ||
*/ | ||
class GridFieldExternalLink extends GridFieldDataColumns { | ||
|
||
/** | ||
* Add a column for the actions | ||
* | ||
* @param type $gridField | ||
* @param array $columns | ||
*/ | ||
public function augmentColumns($gridField, &$columns) { | ||
if(!in_array('Actions', $columns)) $columns[] = 'Actions'; | ||
} | ||
|
||
/** | ||
* 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'); | ||
} | ||
|
||
/** | ||
* Add the title | ||
* | ||
* @param GridField $gridField | ||
* @param string $columnName | ||
* @return array | ||
*/ | ||
public function getColumnMetadata($gridField, $columnName) { | ||
if($columnName == 'Actions') { | ||
return array('title' => ''); | ||
} | ||
return array(); | ||
} | ||
|
||
/** | ||
* Which columns are handled by this component | ||
* | ||
* @param type $gridField | ||
* @return type | ||
*/ | ||
public function getColumnsHandled($gridField) { | ||
return array('Actions'); | ||
} | ||
|
||
/** | ||
* @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' => method_exists($record, 'getExternalLink') ? $record->getExternalLink() : $record->ExternalLink | ||
)); | ||
|
||
return $data->renderWith('GridFieldExternalLink'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a href="$Link" target="_blank" title="<% _t('GridFieldExtensions.ExternalLink','External Link') %>"><% _t('GridFieldExtensions.ExternalLink','External Link') %></a> |