2012-03-06 12:57:16 +01:00
|
|
|
<?php
|
2013-05-20 12:18:07 +02:00
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Forms\GridField;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
use SilverStripe\View\ArrayData;
|
|
|
|
use SilverStripe\View\SSViewer;
|
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
/**
|
2014-08-15 08:53:05 +02:00
|
|
|
* Provides the entry point to editing a single record presented by the
|
2013-05-20 12:18:07 +02:00
|
|
|
* {@link GridField}.
|
|
|
|
*
|
2014-08-15 08:53:05 +02:00
|
|
|
* Doesn't show an edit view on its own or modifies the record, but rather
|
|
|
|
* relies on routing conventions established in {@link getColumnContent()}.
|
2013-05-20 12:18:07 +02:00
|
|
|
*
|
2014-08-15 08:53:05 +02:00
|
|
|
* The default routing applies to the {@link GridFieldDetailForm} component,
|
2013-05-20 12:18:07 +02:00
|
|
|
* which has to be added separately to the {@link GridField} configuration.
|
2012-03-06 12:57:16 +01:00
|
|
|
*/
|
2012-03-09 00:54:02 +01:00
|
|
|
class GridFieldEditButton implements GridField_ColumnProvider {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
/**
|
|
|
|
* Add a column 'Delete'
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2013-06-21 00:32:08 +02:00
|
|
|
* @param GridField $gridField
|
2014-08-15 08:53:05 +02:00
|
|
|
* @param array $columns
|
2012-03-06 12:57:16 +01:00
|
|
|
*/
|
|
|
|
public function augmentColumns($gridField, &$columns) {
|
|
|
|
if(!in_array('Actions', $columns))
|
|
|
|
$columns[] = 'Actions';
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
/**
|
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) {
|
2016-07-01 03:37:29 +02:00
|
|
|
return array('class' => 'grid-field__col-compact');
|
2012-03-06 12:57:16 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
/**
|
2014-08-15 08:53:05 +02:00
|
|
|
* Add the title
|
|
|
|
*
|
2012-03-06 12:57:16 +01:00
|
|
|
* @param GridField $gridField
|
|
|
|
* @param string $columnName
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumnMetadata($gridField, $columnName) {
|
|
|
|
if($columnName == 'Actions') {
|
|
|
|
return array('title' => '');
|
|
|
|
}
|
2016-08-23 04:32:26 +02:00
|
|
|
return [];
|
2012-03-06 12:57:16 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
/**
|
|
|
|
* Which columns are handled by this component
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2013-06-21 00:32:08 +02:00
|
|
|
* @param GridField $gridField
|
2014-08-15 08:53:05 +02:00
|
|
|
* @return array
|
2012-03-06 12:57:16 +01:00
|
|
|
*/
|
|
|
|
public function getColumnsHandled($gridField) {
|
|
|
|
return array('Actions');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
/**
|
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
|
2014-08-15 08:53:05 +02:00
|
|
|
* @return array
|
2012-03-06 12:57:16 +01:00
|
|
|
*/
|
|
|
|
public function getActions($gridField) {
|
|
|
|
return array();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
/**
|
|
|
|
* @param GridField $gridField
|
|
|
|
* @param DataObject $record
|
|
|
|
* @param string $columnName
|
2016-08-23 04:32:26 +02:00
|
|
|
* @return string The HTML for the column
|
2012-03-06 12:57:16 +01:00
|
|
|
*/
|
|
|
|
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')
|
|
|
|
));
|
|
|
|
|
2016-08-23 04:32:26 +02:00
|
|
|
$template = SSViewer::get_templates_by_class($this, '', __CLASS__);
|
|
|
|
return $data->renderWith($template);
|
2012-03-06 12:57:16 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
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) {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-06 12:57:16 +01:00
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|