mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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 <dhensby@users.noreply.github.com> Co-authored-by: Daniel Hensby <dhensby@users.noreply.github.com>
This commit is contained in:
parent
cc8287c99e
commit
4cd6b1434a
@ -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()
|
||||
]);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user