From 8a9e07591433cb40e6eaf2762be27f35bd165373 Mon Sep 17 00:00:00 2001 From: Peter Thaleikis Date: Thu, 10 Sep 2015 21:30:10 +1200 Subject: [PATCH 1/3] Allowing to refer to external links from a modeladmin --- code/GridFieldExternalLink.php | 67 ++++++++++++++++++++++++++++++ templates/GridFieldExternalLink.ss | 1 + 2 files changed, 68 insertions(+) create mode 100644 code/GridFieldExternalLink.php create mode 100644 templates/GridFieldExternalLink.ss diff --git a/code/GridFieldExternalLink.php b/code/GridFieldExternalLink.php new file mode 100644 index 00000000..94c970bc --- /dev/null +++ b/code/GridFieldExternalLink.php @@ -0,0 +1,67 @@ + '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'); + } +} diff --git a/templates/GridFieldExternalLink.ss b/templates/GridFieldExternalLink.ss new file mode 100644 index 00000000..52013e64 --- /dev/null +++ b/templates/GridFieldExternalLink.ss @@ -0,0 +1 @@ +<% _t('GridFieldExtensions.ExternalLink','External Link') %> From 9a253f27f271af0e752334369709b889e7dfc742 Mon Sep 17 00:00:00 2001 From: Peter Thaleikis Date: Mon, 14 Sep 2015 17:15:45 +1200 Subject: [PATCH 2/3] using hasmethod instead of method_exists --- code/GridFieldExternalLink.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/GridFieldExternalLink.php b/code/GridFieldExternalLink.php index 94c970bc..0c0e2820 100644 --- a/code/GridFieldExternalLink.php +++ b/code/GridFieldExternalLink.php @@ -59,7 +59,7 @@ public function getColumnsHandled($gridField) { */ public function getColumnContent($gridField, $record, $columnName) { $data = new ArrayData(array( - 'Link' => method_exists($record, 'getExternalLink') ? $record->getExternalLink() : $record->ExternalLink + 'Link' => $record->hasMethod('getExternalLink') ? $record->getExternalLink() : $record->ExternalLink )); return $data->renderWith('GridFieldExternalLink'); From 4c8009ad02735085d6508911634decfc6425a59e Mon Sep 17 00:00:00 2001 From: Peter Thaleikis Date: Mon, 14 Sep 2015 17:17:23 +1200 Subject: [PATCH 3/3] Adding possibility to define a custom text for the link --- code/GridFieldExternalLink.php | 3 ++- templates/GridFieldExternalLink.ss | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/code/GridFieldExternalLink.php b/code/GridFieldExternalLink.php index 0c0e2820..cb54f2ec 100644 --- a/code/GridFieldExternalLink.php +++ b/code/GridFieldExternalLink.php @@ -59,7 +59,8 @@ public function getColumnsHandled($gridField) { */ public function getColumnContent($gridField, $record, $columnName) { $data = new ArrayData(array( - 'Link' => $record->hasMethod('getExternalLink') ? $record->getExternalLink() : $record->ExternalLink + 'Link' => $record->hasMethod('getExternalLink') ? $record->getExternalLink() : $record->ExternalLink, + 'Text' => $record->hasMethod('getExternalLinkText') ? $record->getExternalLinkText() : 'External Link' )); return $data->renderWith('GridFieldExternalLink'); diff --git a/templates/GridFieldExternalLink.ss b/templates/GridFieldExternalLink.ss index 52013e64..cf820246 100644 --- a/templates/GridFieldExternalLink.ss +++ b/templates/GridFieldExternalLink.ss @@ -1 +1 @@ -<% _t('GridFieldExtensions.ExternalLink','External Link') %> +$Text