2012-01-09 11:37:13 +01:00
|
|
|
<?php
|
2012-01-09 17:17:31 +01:00
|
|
|
/**
|
2012-02-27 18:26:11 +01:00
|
|
|
* Provides the entry point to editing a single record presented by the grid.
|
|
|
|
* Doesn't show an edit view on its own or modifies the record, but rather relies on routing conventions
|
|
|
|
* established in {@link getColumnContent()}. The default routing applies to
|
|
|
|
* the {@link GridFieldPopupForms} component, which has to be added separately
|
|
|
|
* to the grid field configuration.
|
2012-01-09 17:17:31 +01:00
|
|
|
*/
|
|
|
|
class GridFieldAction_Edit implements GridField_ColumnProvider {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a column 'Delete'
|
|
|
|
*
|
|
|
|
* @param type $gridField
|
|
|
|
* @param array $columns
|
|
|
|
*/
|
|
|
|
public function augmentColumns($gridField, &$columns) {
|
2012-02-07 23:21:34 +01:00
|
|
|
if(!in_array('Actions', $columns))
|
|
|
|
$columns[] = 'Actions';
|
2012-01-09 17:17:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return any special attributes that will be used for FormField::createTag()
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param DataObject $record
|
|
|
|
* @param string $columnName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumnAttributes($gridField, $record, $columnName) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the title
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param string $columnName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumnMetadata($gridField, $columnName) {
|
2012-02-07 23:21:34 +01:00
|
|
|
if($columnName == 'Actions') {
|
2012-01-09 17:17:31 +01:00
|
|
|
return array('title' => '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Which columns are handled by this component
|
|
|
|
*
|
|
|
|
* @param type $gridField
|
|
|
|
* @return type
|
|
|
|
*/
|
|
|
|
public function getColumnsHandled($gridField) {
|
2012-02-07 23:21:34 +01:00
|
|
|
return array('Actions');
|
2012-01-09 17:17:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Which GridField actions are this component handling
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getActions($gridField) {
|
2012-02-09 02:35:33 +01:00
|
|
|
return array();
|
2012-01-09 17:17:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param DataObject $record
|
|
|
|
* @param string $columnName
|
|
|
|
* @return string - the HTML for the column
|
|
|
|
*/
|
|
|
|
public function getColumnContent($gridField, $record, $columnName) {
|
2012-02-22 04:19:45 +01:00
|
|
|
$data = new ArrayData(array(
|
|
|
|
'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')
|
|
|
|
));
|
|
|
|
|
|
|
|
return $data->renderWith('GridFieldAction_Edit');
|
2012-01-09 17:17:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the actions and apply any changes to the GridField
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param string $actionName
|
|
|
|
* @param mixed $arguments
|
|
|
|
* @param array $data - form data
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-09 11:37:13 +01:00
|
|
|
/**
|
|
|
|
* This class is an GridField Component that add Delete action for Objects in the GridField
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class GridFieldAction_Delete implements GridField_ColumnProvider, GridField_ActionProvider {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a column 'Delete'
|
|
|
|
*
|
|
|
|
* @param type $gridField
|
|
|
|
* @param array $columns
|
|
|
|
*/
|
|
|
|
public function augmentColumns($gridField, &$columns) {
|
2012-02-07 23:21:34 +01:00
|
|
|
if(!in_array('Actions', $columns))
|
|
|
|
$columns[] = 'Actions';
|
2012-01-09 11:37:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return any special attributes that will be used for FormField::createTag()
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param DataObject $record
|
|
|
|
* @param string $columnName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumnAttributes($gridField, $record, $columnName) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the title
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param string $columnName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumnMetadata($gridField, $columnName) {
|
2012-02-07 23:21:34 +01:00
|
|
|
if($columnName == 'Actions') {
|
2012-01-09 17:16:07 +01:00
|
|
|
return array('title' => '');
|
2012-01-09 11:37:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Which columns are handled by this component
|
|
|
|
*
|
|
|
|
* @param type $gridField
|
|
|
|
* @return type
|
|
|
|
*/
|
|
|
|
public function getColumnsHandled($gridField) {
|
2012-02-07 23:21:34 +01:00
|
|
|
return array('Actions');
|
2012-01-09 11:37:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Which GridField actions are this component handling
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getActions($gridField) {
|
|
|
|
return array('deleterecord');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param DataObject $record
|
|
|
|
* @param string $columnName
|
|
|
|
* @return string - the HTML for the column
|
|
|
|
*/
|
|
|
|
public function getColumnContent($gridField, $record, $columnName) {
|
2012-01-09 17:16:07 +01:00
|
|
|
$field = new GridField_Action(
|
|
|
|
$gridField,
|
|
|
|
'DeleteRecord'.$record->ID,
|
|
|
|
_t('GridAction.Delete', "delete"),
|
|
|
|
"deleterecord",
|
|
|
|
array('RecordID' => $record->ID)
|
|
|
|
);
|
2012-01-09 11:37:13 +01:00
|
|
|
$output = $field->Field();
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the actions and apply any changes to the GridField
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param string $actionName
|
|
|
|
* @param mixed $arguments
|
|
|
|
* @param array $data - form data
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
|
|
|
if($actionName == 'deleterecord') {
|
2012-02-09 02:35:33 +01:00
|
|
|
$id = $arguments['RecordID'];
|
|
|
|
$item = $gridField->getList()->byID($id);
|
|
|
|
if(!$item) return;
|
|
|
|
$item->delete();
|
2012-01-09 11:37:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|