silverstripe-framework/forms/gridfield/GridFieldEditButton.php

106 lines
2.5 KiB
PHP
Raw Normal View History

<?php
/**
2014-08-15 08:53:05 +02:00
* Provides the entry point to editing a single record presented by the
* {@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()}.
*
2014-08-15 08:53:05 +02:00
* The default routing applies to the {@link GridFieldDetailForm} component,
* which has to be added separately to the {@link GridField} configuration.
*
* @package forms
* @subpackage fields-gridfield
*/
class GridFieldEditButton implements GridField_ColumnProvider {
2014-08-15 08:53:05 +02:00
/**
* Add a column 'Delete'
2014-08-15 08:53:05 +02:00
*
* @param GridField $gridField
2014-08-15 08:53:05 +02:00
* @param array $columns
*/
public function augmentColumns($gridField, &$columns) {
if(!in_array('Actions', $columns))
$columns[] = 'Actions';
}
2014-08-15 08:53:05 +02:00
/**
* Return any special attributes that will be used for FormField::create_tag()
*
* @param GridField $gridField
* @param DataObject $record
* @param string $columnName
* @return array
*/
public function getColumnAttributes($gridField, $record, $columnName) {
return array('class' => 'col-buttons');
}
2014-08-15 08:53:05 +02:00
/**
2014-08-15 08:53:05 +02:00
* Add the title
*
* @param GridField $gridField
* @param string $columnName
* @return array
*/
public function getColumnMetadata($gridField, $columnName) {
if($columnName == 'Actions') {
return array('title' => '');
}
}
2014-08-15 08:53:05 +02:00
/**
* Which columns are handled by this component
2014-08-15 08:53:05 +02:00
*
* @param GridField $gridField
2014-08-15 08:53:05 +02:00
* @return array
*/
public function getColumnsHandled($gridField) {
return array('Actions');
}
2014-08-15 08:53:05 +02:00
/**
* Which GridField actions are this component handling.
*
* @param GridField $gridField
2014-08-15 08:53:05 +02:00
* @return array
*/
public function getActions($gridField) {
return array();
}
2014-08-15 08:53:05 +02:00
/**
* @param GridField $gridField
* @param DataObject $record
* @param string $columnName
*
2014-08-15 08:53:05 +02:00
* @return string - the HTML for the column
*/
public function getColumnContent($gridField, $record, $columnName) {
// No permission checks, handled through GridFieldDetailForm,
// which can make the form readonly if no edit permissions are available.
$data = new ArrayData(array(
'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')
));
return $data->renderWith('GridFieldEditButton');
}
2014-08-15 08:53:05 +02: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) {
2014-08-15 08:53:05 +02:00
}
}