Blame view

framework/forms/gridfield/GridFieldEditButton.php 2.51 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  <?php
  
  /**
   * 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.
   *
   * @package forms
   * @subpackage fields-gridfield
   */
  class GridFieldEditButton implements GridField_ColumnProvider {
  	
  	/**
  	 * Add a column 'Delete'
  	 * 
  	 * @param type $gridField
  	 * @param array $columns 
  	 */
  	public function augmentColumns($gridField, &$columns) {
  		if(!in_array('Actions', $columns))
  			$columns[] = 'Actions';
  	}
  	
  	/**
  	 * 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');
  	}
  	
  	/**
  	 * 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
  	 * 
  	 * @param type $gridField
  	 * @return type 
  	 */
  	public function getColumnsHandled($gridField) {
  		return array('Actions');
  	}
  	
  	/**
  	 * Which GridField actions are this component handling.
  	 *
  	 * @param GridField $gridField
  	 * @return array 
  	 */
  	public function getActions($gridField) {
  		return array();
  	}
  	
  	/**
  	 * @param GridField $gridField
  	 * @param DataObject $record
  	 * @param string $columnName
  	 *
  	 * @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');
  	}
  	
  	/**
  	 * 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) {
  		
  	}
  }