From 4cd6b1434ab2534f536f90335f4ad570181c98b4 Mon Sep 17 00:00:00 2001 From: GuySartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Mon, 19 Jul 2021 03:54:22 +1200 Subject: [PATCH] ENH Reduce duplication of code in GridField view and edit buttons. (#9953) * ENH Reduce duplication of code in GridField view and edit buttons. * Fix syntax error Co-authored-by: Daniel Hensby Co-authored-by: Daniel Hensby --- src/Forms/GridField/GridFieldEditButton.php | 10 +++++++--- src/Forms/GridField/GridFieldViewButton.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Forms/GridField/GridFieldEditButton.php b/src/Forms/GridField/GridFieldEditButton.php index 2977dd3c6..41a5b606b 100644 --- a/src/Forms/GridField/GridFieldEditButton.php +++ b/src/Forms/GridField/GridFieldEditButton.php @@ -63,7 +63,7 @@ class GridFieldEditButton implements GridField_ColumnProvider, GridField_ActionP /** * @inheritdoc */ - public function getUrl($gridField, $record, $columnName) + public function getUrl($gridField, $record, $columnName, $addState = true) { $link = Controller::join_links( $gridField->Link('item'), @@ -71,7 +71,11 @@ class GridFieldEditButton implements GridField_ColumnProvider, GridField_ActionP 'edit' ); - return $this->getStateManager()->addStateToURL($gridField, $link); + if ($addState) { + $link = $this->getStateManager()->addStateToURL($gridField, $link); + } + + return $link; } /** @@ -149,7 +153,7 @@ class GridFieldEditButton implements GridField_ColumnProvider, GridField_ActionP // which can make the form readonly if no edit permissions are available. $data = new ArrayData([ - 'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit'), + 'Link' => $this->getURL($gridField, $record, $columnName, false), 'ExtraClass' => $this->getExtraClass() ]); diff --git a/src/Forms/GridField/GridFieldViewButton.php b/src/Forms/GridField/GridFieldViewButton.php index 743350867..e99b40033 100644 --- a/src/Forms/GridField/GridFieldViewButton.php +++ b/src/Forms/GridField/GridFieldViewButton.php @@ -65,7 +65,7 @@ class GridFieldViewButton implements GridField_ColumnProvider, GridField_ActionM return null; } $data = new ArrayData([ - 'Link' => Controller::join_links($field->Link('item'), $record->ID, 'view') + 'Link' => $this->getURL($field, $record, $col), ]); $template = SSViewer::get_templates_by_class($this, '', __CLASS__); return $data->renderWith($template);