1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class GridFieldExtraColumns implements GridField_ColumnProvider |
|
|
|
|
5
|
|
|
{ |
6
|
|
|
protected $field = ''; |
7
|
|
|
|
8
|
|
|
public function __construct($field) |
9
|
|
|
{ |
10
|
|
|
$this->field = $field; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
public function augmentColumns($gridField, &$columns) |
14
|
|
|
{ |
15
|
|
|
array_unshift($columns, $this->field); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function getColumnAttributes($gridField, $record, $columnName) |
19
|
|
|
{ |
20
|
|
|
return array( |
21
|
|
|
'data-extrafield' => '1', |
22
|
|
|
'data-url' => '/admin/boardcheck', |
23
|
|
|
'data-field' => $this->field, |
24
|
|
|
'data-id' => $record->ID, |
25
|
|
|
'onclick' => "if(event.stopPropagation){event.stopPropagation();}event.cancelBubble=true;var val = prompt('Enter value');var t = jQuery(this);t.html(val);var model = t.parents('tr').data('class');jQuery.post(t.data('url') + '/' + model + '/extrafields/' + t.data('id'),{field:t.data('field'),table:t.data('table'),id:t.data('id'),value:val});return false" |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getColumnContent($gridField, $record, $columnName) |
30
|
|
|
{ |
31
|
|
|
$res = $gridField->getList()->getExtraData($this->field, $record->ID); |
|
|
|
|
32
|
|
|
if ($res) { |
33
|
|
|
return $res[$this->field]; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getColumnMetadata($gridField, $columnName) |
38
|
|
|
{ |
39
|
|
|
return array('title' => $this->field); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getColumnsHandled($gridField) |
43
|
|
|
{ |
44
|
|
|
$form = $gridField->getConfig()->getComponentByType('GridFieldDetailForm'); |
45
|
|
|
if ($form) { |
46
|
|
|
$field = $this->field; |
47
|
|
|
//this does nothing :( |
48
|
|
|
$form->setItemEditFormCallback(function ($form, $components) use ($field) { |
|
|
|
|
49
|
|
|
$form->addFieldToTab('Root.Main', new TextField($field)); |
50
|
|
|
}); |
51
|
|
|
} |
52
|
|
|
return array($this->field); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.