2012-03-06 12:57:16 +01:00
|
|
|
<?php
|
2013-05-20 12:18:07 +02:00
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
/**
|
2013-05-20 12:18:07 +02:00
|
|
|
* Provides the entry point to editing a single record presented by the
|
|
|
|
* {@link GridField}.
|
|
|
|
*
|
|
|
|
* 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 GridFieldDetailForm} component,
|
|
|
|
* which has to be added separately to the {@link GridField} configuration.
|
|
|
|
*
|
2013-11-29 05:12:47 +01:00
|
|
|
* @package forms
|
2013-05-20 12:18:07 +02:00
|
|
|
* @subpackage fields-gridfield
|
2012-03-06 12:57:16 +01:00
|
|
|
*/
|
2012-03-09 00:54:02 +01:00
|
|
|
class GridFieldEditButton implements GridField_ColumnProvider {
|
2012-03-06 12:57:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a column 'Delete'
|
|
|
|
*
|
2013-06-21 00:32:08 +02:00
|
|
|
* @param GridField $gridField
|
2012-03-06 12:57:16 +01:00
|
|
|
* @param array $columns
|
|
|
|
*/
|
|
|
|
public function augmentColumns($gridField, &$columns) {
|
|
|
|
if(!in_array('Actions', $columns))
|
|
|
|
$columns[] = 'Actions';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-15 02:19:57 +01:00
|
|
|
* Return any special attributes that will be used for FormField::create_tag()
|
2012-03-06 12:57:16 +01:00
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param DataObject $record
|
|
|
|
* @param string $columnName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumnAttributes($gridField, $record, $columnName) {
|
2012-03-12 10:23:59 +01:00
|
|
|
return array('class' => 'col-buttons');
|
2012-03-06 12:57:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the title
|
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param string $columnName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumnMetadata($gridField, $columnName) {
|
|
|
|
if($columnName == 'Actions') {
|
|
|
|
return array('title' => '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Which columns are handled by this component
|
|
|
|
*
|
2013-06-21 00:32:08 +02:00
|
|
|
* @param GridField $gridField
|
|
|
|
* @return array
|
2012-03-06 12:57:16 +01:00
|
|
|
*/
|
|
|
|
public function getColumnsHandled($gridField) {
|
|
|
|
return array('Actions');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-20 12:18:07 +02:00
|
|
|
* Which GridField actions are this component handling.
|
2012-03-06 12:57:16 +01:00
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getActions($gridField) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param DataObject $record
|
|
|
|
* @param string $columnName
|
2013-05-20 12:18:07 +02:00
|
|
|
*
|
2012-03-06 12:57:16 +01:00
|
|
|
* @return string - the HTML for the column
|
|
|
|
*/
|
|
|
|
public function getColumnContent($gridField, $record, $columnName) {
|
2012-12-17 00:47:23 +01:00
|
|
|
// No permission checks, handled through GridFieldDetailForm,
|
|
|
|
// which can make the form readonly if no edit permissions are available.
|
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
$data = new ArrayData(array(
|
|
|
|
'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')
|
|
|
|
));
|
|
|
|
|
2012-03-09 00:54:02 +01:00
|
|
|
return $data->renderWith('GridFieldEditButton');
|
2012-03-06 12:57:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-20 12:18:07 +02:00
|
|
|
* Handle the actions and apply any changes to the GridField.
|
2012-03-06 12:57:16 +01:00
|
|
|
*
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param string $actionName
|
|
|
|
* @param mixed $arguments
|
|
|
|
* @param array $data - form data
|
2013-05-20 12:18:07 +02:00
|
|
|
*
|
2012-03-06 12:57:16 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
|
|
|
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|