From 599a4420bf0d982343faa6145afaf6592566bb40 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Fri, 13 Jul 2018 10:45:13 +1200 Subject: [PATCH] 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 --- lang/en.yml | 2 ++ src/Forms/GridField/GridFieldViewButton.php | 35 ++++++++++++++++++- .../Forms/GridField/GridFieldViewButton.ss | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lang/en.yml b/lang/en.yml index 56654a39d..e10f5053f 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -97,6 +97,8 @@ en: Save: Save SilverStripe\Forms\GridField\GridFieldEditButton: EDIT: Edit + SilverStripe\Forms\GridField\GridFieldViewButton: + VIEW: View SilverStripe\Forms\GridField\GridFieldGroupDeleteAction: UnlinkSelfFailure: 'Cannot remove yourself from this group, you will lose admin rights' SilverStripe\Forms\GridField\GridFieldPaginator: diff --git a/src/Forms/GridField/GridFieldViewButton.php b/src/Forms/GridField/GridFieldViewButton.php index cd5c32aff..743350867 100644 --- a/src/Forms/GridField/GridFieldViewButton.php +++ b/src/Forms/GridField/GridFieldViewButton.php @@ -11,8 +11,41 @@ use SilverStripe\View\SSViewer; * disabled by default and intended for use in readonly {@link GridField} * instances. */ -class GridFieldViewButton implements GridField_ColumnProvider +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) { diff --git a/templates/SilverStripe/Forms/GridField/GridFieldViewButton.ss b/templates/SilverStripe/Forms/GridField/GridFieldViewButton.ss index f0c97e98e..45c5a2993 100644 --- a/templates/SilverStripe/Forms/GridField/GridFieldViewButton.ss +++ b/templates/SilverStripe/Forms/GridField/GridFieldViewButton.ss @@ -1,3 +1,3 @@ - + View